Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions RoundedCorners@klangman/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# Changelog

## 1.0.2

* Improved Cinnamon 6.8 support.
* Added colored, gradient and rainbow animated shadows.
* Added border color option to match the theme's accent color.
* Fix the effects on scaled display (thanks to [thebrickmaster626-bit](https://github.com/klangman/CinnamonRoundedCorners/pulls?q=is%3Apr+state%3Aclosed+author%3Athebrickmaster626-bit) for the fix).
* Fix for window size tracking when expanding the window (the issue was particularly visible on left side window resizing).
* Fix an issue when unminimizing an Electron application.
* Fix missed rounding when an XWayland surface attaches late (thanks to [Geequlim](https://github.com/klangman/CinnamonRoundedCorners/pulls?q=is%3Apr+state%3Aclosed+author%3AGeequlim) for the fix).
* Fixed an issue where the windows border and shadow is drawn before the windows first frame is drawn (happens for slow starting applications).

## 1.0.1

* This fixes an issue where the VRAM is consumed at a high rate during resizing a window or when moving a window when it's partly off the screen. If the resize/movement continued for a number of seconds it could lead Cinnamon to becoming unresponsive for quite a time until a GC cycle is started.

## 1.0.0

* Initial version committed to cinnamon spices
12 changes: 7 additions & 5 deletions RoundedCorners@klangman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ A Cinnamon extension that allows you to round the corners of windows with custom
* Round window bottoms to match window tops.
* Increase the radius of your theme's top corner rounding
* Customize your window border
* Use different border colors for different application, and/or the focused window
* Use different border colors for different applications, and/or the focused window
* Customize your window shadows
* Use different shadow strength the focused window
* Use different shadow strength for the focused window

## Features

- Allows you to Round the top and bottom corners of application windows.
- Allows you to round the top and bottom corners of application windows.
- Adds custom borders and shadows to windows that have rounding effects applied
- Allow you to exclude specific applications when rounding <u>is</u> enabled by default
- Allows you to select specific applications to round when rounding is <u>not</u> enabled by default
- Allows you to specify different borders setting (i.e colors) for different application windows
- Allows for different custom borders and shadow strengths for the focused window vs. all the unfocused windows.
- Has a border matching option allowing the border of the rounded corners to match the windows natural borders
- Supports Gtk3, libhandy, Gtk4, Adwaita and Qt application windows. It should work reasonably well for just about any type of window
- An option to match border color with the theme's accent color
- An option to make colored, gradient and animated rainbow shadows

## Requirements

Expand Down Expand Up @@ -85,7 +87,7 @@ Some windows use their own custom title-bars. For those applications you will ne

**<u>Shadows:</u>**

The stock shadows are by necessity removed by the corner effect. So this extension tells Cinnamon not to draw the stock shadows at all for windows that have cornet effects applied. The shadows need to be recreated for the clipped corners anyhow. A new shadow is therefore created in its place. By using a completely new shadow effect it gives you more control over how shadows appear. Keep in mind that the new shadow effect is only possible for windows that also have their corners rounded, see the "Corners" tab in the settings.
The stock shadows are by necessity removed by the corner effect. So this extension tells Cinnamon not to draw the stock shadows at all for windows that have corner effects applied. The shadows need to be recreated for the clipped corners anyhow. A new shadow is therefore created in its place. By using a completely new shadow effect it gives you more control over how shadows appear. Keep in mind that the new shadow effect is only possible for windows that also have their corners rounded, see the "Corners" tab in the settings.

**<u>Borders:</u>**

Expand All @@ -108,7 +110,7 @@ There is a bug in the Clutter.ShaderEffect class causing a VRAM memory leak. A [

Please leave a comment here on cinnamon-spices.linuxmint.com or you can create an issue on my [Github](https://github.com/klangman/CinnamonRoundedCorners) to give me feedback, make a suggestion or to report any issues you find.

If you like this Cinnamon extension, please give it a "star" here any maybe on my [Github](https://github.com/klangman/CinnamonRoundedCorners) repository as well to encourage me to continue working on the project. Thanks!
If you like this Cinnamon extension, please give it a "star" here and maybe on my [Github](https://github.com/klangman/CinnamonRoundedCorners) repository as well to encourage me to continue working on the project. Thanks!

## Credits

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import os
import sys
import re
import operator
import gi
import gettext

Expand Down Expand Up @@ -298,6 +300,154 @@ def patched_init(self, *args, _original_init=List.__init__, **kwargs):
_patch_list_widget()


# Dependency strings with "&" (and) and "|" (or), copied from Blur Cinnamon
OPERATIONS = ['<=', '>=', '<', '>', '!=', '=']

OPERATIONS_MAP = {'<': operator.lt, '<=': operator.le, '>': operator.gt, '>=': operator.ge, '!=': operator.ne, '=': operator.eq}

def is_number(s):
try:
float(s) # Try converting to a float
return True
except ValueError:
return False

def get_constant(settings, string):
if is_number(string):
value = float(string);
elif string.lower() == 'true':
value = True
elif string.lower() == "false":
value = False
else:
value = string
return value

def customRevealerInit(self, settings, key):
# Not super(JSONSettingsRevealer, ...): this module can't name the class xlet-settings actually uses
Gtk.Revealer.__init__(self)
self.settings = settings

# Split the dependencies into a list of keys, operations and constants
expression = re.split(r'(!=|<=|>=|[<>=&| ])', key)
# Remove any blank entries and any whitespace within entries
self.expression = [item.strip() for item in expression if item.strip()]

# Listen to any keys found in the expression,
# expand all compares, decode constants,
# decode compare operators and check for errors
key = None
idx = 0
count = len(self.expression)
listening = []
#print( f"Preparing dependency: {self.expression}" )
while idx < count:
element = self.expression[idx]
if element == '&' or element == '|':
pass
elif element in OPERATIONS: # ... key op constant ...
self.expression[idx] = OPERATIONS_MAP[element]
key = self.expression[idx-1]
if idx+1 < count and self.expression[idx+1] != '&' and self.expression[idx+1] != '|':
self.expression[idx+1] = get_constant(self.settings, self.expression[idx+1])
else:
self.expression.insert(idx+1, False)
count += 1
idx += 1
elif element[0] == '!': # ... !key ...
key = element[1:]
self.expression[idx] = key
self.expression.insert(idx+1, False)
self.expression.insert(idx+1, operator.eq)
idx += 2
count += 2
elif idx == count-1 or self.expression[idx+1] == '&' or self.expression[idx+1] == '|': # standalone key
key = element
self.expression.insert(idx+1, True)
self.expression.insert(idx+1, operator.eq)
idx += 2
count += 2
if key:
if self.settings.has_key(key):
if key not in listening:
self.settings.listen(key, self.key_changed)
listening.append(key)
else:
print( f"Error in json dependency: \"{key}\" is not a valid key" )
if idx+1 < count and self.expression[idx+1] != '&' and self.expression[idx+1] != '|':
print( f"Error in json dependency: Unexpected expression \"{self.expression[idx+1]}\"" )
self.expression = self.expression[:idx+1] # remove the remaining elements since something is wrong with the syntax
break
key = None
idx += 1

self.box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
Gtk.Revealer.add(self, self.box)

self.set_transition_type(Gtk.RevealerTransitionType.SLIDE_DOWN)
self.set_transition_duration(150)

# Fake out a key_changed event so that we have the correct reveal state
self.key_changed(None, None)


def customRevealerKeyChanged(self, key, value):
evaluate = []
count = len(self.expression)
#print( f"Evaluating expression: {self.expression}" )

# Go through the expression to evaluate all the compares
# The init ensures that the list has this format: key op const [ <&/|> key op const ]...
idx = 0
while idx < count:
lhs = self.settings.get_value(self.expression[idx]) #get_value(self.settings, self.expression[idx])
op = self.expression[idx+1]
rhs = self.expression[idx+2]
evaluate.append( op(lhs, rhs) )
idx += 3
if idx < count:
evaluate.append( self.expression[idx] )
idx += 1
#print( f"Post compare evaluation: {evaluate}" )

# Handle all the "and" operations first in accordance with the logical order of operations
while "&" in evaluate:
idx = evaluate.index("&")
result = (evaluate[idx-1] and evaluate[idx+1])
evaluate[idx-1:idx+2] = [] ## remove 3 elements: idx-1 through idx+1
evaluate.insert(idx-1, result);
#print( f"After evaluating the ands: {evaluate}" )

# Handle all the "or" operations (there should be nothing but "or" operations at this point)
while "|" in evaluate:
idx = evaluate.index("|")
result = (evaluate[idx-1] or evaluate[idx+1])
evaluate[idx-1:idx+2] = [] ## remove 3 elements: idx-1 through idx+1
evaluate.insert(idx-1, result);
#print( f"After evaluating ors: {evaluate}" )

# At this point we should only have one entry in the list, the final result
#print( f"Final result: {evaluate}" )
self.set_reveal_child(evaluate[0])


# Monkey patch the JSONSettingsRevealer to use our custom methods which allows for "and" and "or" dependency operations.
# xlet-settings imports this module when it builds the first "custom" widget, so the patch is applied then (at the
# bottom of this file). That means a custom widget must come before any widget or section with a dependency.
#
# Cinnamon 6.6 and older import the settings module as "JsonSettingsWidgets", newer versions as
# "bin.JsonSettingsWidgets". Importing the name Cinnamon didn't use would load a second, unused copy of the module
# (and patching that copy does nothing), so patch whichever copies are already loaded.
def patch_revealer():
for name in ("bin.JsonSettingsWidgets", "JsonSettingsWidgets"):
module = sys.modules.get(name)
revealer = getattr(module, "JSONSettingsRevealer", None)
if revealer is not None and revealer.__init__ is not customRevealerInit:
print( f"Monkey patching {name}.JSONSettingsRevealer methods" )
revealer.__init__ = customRevealerInit
revealer.key_changed = customRevealerKeyChanged


# An About page Widget with an optional image and a centered label that supports markup
class About(SettingsWidget):
def __init__(self, info, key, settings):
Expand Down Expand Up @@ -346,3 +496,6 @@ def __init__(self, info, key, settings):

self.pack_start(icon, False, False, 0)
self.pack_start(self.label, True, True, 0)


patch_revealer()
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ const Cogl = imports.gi.Cogl;
const Gio = imports.gi.Gio;
const GLib = imports.gi.GLib;

const EffectBaseModule = (typeof global === 'undefined') ? null : require("./effect_base");
// Cinnamon 6.7.6+ deprecates require() in favour of the extension's native importer (see extension.js)
function loadEffectBase() {
if (typeof global === 'undefined')
return null;
const Extension = imports.ui.extension;
const Me = (typeof Extension.getCurrentExtension === 'function') ? Extension.getCurrentExtension() : null;
return (Me && Me.imports) ? Me.imports.effect_base : require("./effect_base");
}
const EffectBaseModule = loadEffectBase();
const EffectBase = EffectBaseModule ? EffectBaseModule.EffectBase : null;

const SHADER_FILENAME = 'corner.glsl';
Expand Down Expand Up @@ -477,7 +485,8 @@ var ShadowEffect = (typeof global === 'undefined') ? null :

// width/height: the shadow actor's size
// rect: the window's rounded rectangle in the shadow actor's pixels [x0, y0, x1, y1]
// shadow: {size, opacity (0..1), offsetY, radius, top, bottom}
// shadow: {size, opacity (0..1), offsetY, radius, top, bottom,
// colorMode (0..3), color1/color2 ([r, g, b, a] 0..1), angle (degrees), glow (0..1)}
update(width, height, rect, shadow) {
let fx = fboGeometry(0, width);
let fy = fboGeometry(0, height);
Expand All @@ -489,13 +498,33 @@ var ShadowEffect = (typeof global === 'undefined') ? null :
this.set_uniform_value('rect_y0', asFloat(rect[1]));
this.set_uniform_value('rect_x1', asFloat(rect[2]));
this.set_uniform_value('rect_y1', asFloat(rect[3]));
this.set_uniform_value('radius', asFloat(Math.min(shadow.radius, (rect[2] - rect[0]) / 2, (rect[3] - rect[1]) / 2)));
// Scaled like CornerEffect's radius (see update_radius()), so the shadow follows
// the window's corners on HiDPI desktops; rect is already in physical pixels
let scale = St.ThemeContext.get_for_stage(global.stage).scale_factor;
this.set_uniform_value('radius', asFloat(Math.min(shadow.radius * scale, (rect[2] - rect[0]) / 2, (rect[3] - rect[1]) / 2)));
this.set_uniform_value('corners_top', shadow.top ? 1 : 0);
this.set_uniform_value('corners_bottom', shadow.bottom ? 1 : 0);
this.set_uniform_value('shadow_size', asFloat(shadow.size));
this.set_uniform_value('shadow_opacity', asFloat(shadow.opacity));
this.set_uniform_value('shadow_offset_y', asFloat(shadow.offsetY));
this.set_uniform_value('cutout_inset', asFloat(shadow.cutoutInset || 0));
let c1 = shadow.color1 || [0, 0, 0, 1];
let c2 = shadow.color2 || c1;
this.set_uniform_value('shadow_color_mode', Math.round(shadow.colorMode || 0));
['r', 'g', 'b', 'a'].forEach((ch, i) => {
this.set_uniform_value(`color1_${ch}`, asFloat(c1[i] ?? 1));
this.set_uniform_value(`color2_${ch}`, asFloat(c2[i] ?? 1));
});
this.set_uniform_value('grad_angle', asFloat((shadow.angle || 0) * Math.PI / 180));
this.set_uniform_value('glow', asFloat(shadow.glow || 0));
}

// Rotates the rainbow (in turns, 0..1). Only the shadow's own actor needs repainting.
setHueOffset(turns) {
this.set_uniform_value('hue_offset', asFloat(turns));
let actor = this.get_actor();
if (actor)
actor.queue_redraw();
}
});

Expand Down
Loading
Loading