Skip to content

Commit

Permalink
[adjacent-windows@klangman] Add two algorithm tuning options (#588)
Browse files Browse the repository at this point in the history
1. Added two configuration options to offer some advanced controls over how the algorithm works when using the "Closest with a visible corner" setting.
2. Moved files to a 5.4 directory as an added protection ensuring that the extension is only used in Cinnamon 5.4 or higher.
3. Fixed some typos in the README.md file.
  • Loading branch information
klangman authored Mar 26, 2024
1 parent e758fee commit bc40b86
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 56 deletions.
8 changes: 7 additions & 1 deletion adjacent-windows@klangman/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.1.0

* Added two configuration options to offer some advanced controls over how the algorithm works when using the "Closest with a visible corner" window selection option. These options might help some people achieve a window selection behaviour that is more to their liking.
* Moved files to a 5.4 directory as an added protection ensuring that the extension is only used in Cinnamon 5.4 or higher.
* Fixed some typos in the README.md

## 1.0.0

* Initial verion commited to cinnamon spices
* Initial version commited to cinnamon spices
6 changes: 3 additions & 3 deletions adjacent-windows@klangman/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Adjacent Windows
A Cinnamon extension that allows you to define hot keys which will activate the nearest window to the current window on the left, right, above, below or underneath. There is also an option (disabled by default) to undo the window change and activate the window that previously had the focus. With this extension you can easily switch the window focus without reaching for the mouse and it's faster than using Alt-TAB. It's particularly useful for people frequently who use window tiling.
A Cinnamon extension that allows you to define hotkeys which will activate the nearest window to the current window on the left, right, above, below or underneath. There is also an option (disabled by default) to undo the window change and activate the window that previously had the focus. With this extension you can easily change the window focus without reaching for the mouse and it's faster than using Alt-TAB. It's particularly useful for people who frequently use window tiling.

By default the Super+Alt+(arrow-keys) are defined as the hotkeys to move to adjacent windows, but this can be changed in the configuration. If you like, for instance, the Vim key bindings, you could change them to Super+h/j/k/l. The default hotkey for activating windows underneath the current window is Super+Alt+Insert (Keypad)
By default the Super+Alt+(arrow-keys) are defined as the hotkeys to move to adjacent windows, but this can be changed in the configuration. If for example, you like the Vim key bindings, you could change the hotkeys to be Super+h/j/k/l. The default hotkey for activating windows underneath the current window is Super+Alt+Insert (Keypad).

## Requirements
This applet requires at least Mint 21 / Cinnamon 5.4 because the Meta.Window.get_frame_rect() API is needed.
This extension requires at least Linux Mint 21 / Cinnamon 5.4 because the Meta.Window.get_frame_rect() API is needed.

## Installation
1. Right click on the cinnamon panel and click "System Settings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ class AdjacentWindows {
let candidateList = [];
let windowVisibilityList = [];
let allowOtherMon = this.settings.getValue("include-other-monitors");
let zoneReductionPercent = this.settings.getValue("boost-restriction");
let zoneReduction = Math.round( ((direction == Direction.Left || direction == Direction.Right)? focusedRec.height : focusedRec.width) * (zoneReductionPercent/100) / 2 );
let cornerAllowance = this.settings.getValue("overlap-allowance");

// Sort the list of windows in z-order (most recently focused is first in the list).
windowList.sort(function(a, b) {return b.user_time - a.user_time;});
Expand All @@ -293,31 +296,43 @@ class AdjacentWindows {
if (metaWindow != focusedWindow) {
if (direction == Direction.Left) {
if (rec.x < focusedRec.x) {
windowVisibilityList[idx].overlapping = (rec.y < focusedRec.y+focusedRec.height && rec.y+rec.height > focusedRec.y);
windowVisibilityList[idx].rec.width = Math.min(rec.width, focusedRec.x-1-rec.x);
windowVisibilityList[idx].cornerVisibility = this.getCornerVisibility( windowVisibilityList[idx], windowList, rec.x, rec.x+rec.width, rec.y, rec.y+rec.height );
candidateList.push(windowVisibilityList[idx]);
windowVisibilityList[idx].overlapping = (rec.y < focusedRec.y+focusedRec.height-zoneReduction && rec.y+rec.height > focusedRec.y+zoneReduction);
rec.width = Math.min(rec.width, focusedRec.x-1-rec.x);
if (rec.width >= cornerAllowance && rec.height >= cornerAllowance) {
windowVisibilityList[idx].cornerVisibility = this.getCornerVisibility( windowVisibilityList[idx], windowList, rec.x+cornerAllowance, rec.x+rec.width-cornerAllowance, rec.y+cornerAllowance, rec.y+rec.height-cornerAllowance );
candidateList.push(windowVisibilityList[idx]);
}
}
} else if (direction == Direction.Right) {
if (rec.x+rec.width > focusedRec.x+focusedRec.width) {
windowVisibilityList[idx].overlapping = (rec.y < focusedRec.y+focusedRec.height && rec.y+rec.height > focusedRec.y);
windowVisibilityList[idx].rec.x = Math.max(rec.x, focusedRec.x+focusedRec.width+1);
windowVisibilityList[idx].cornerVisibility = this.getCornerVisibility( windowVisibilityList[idx], windowList, rec.x, rec.x+rec.width, rec.y, rec.y+rec.height );
candidateList.push(windowVisibilityList[idx]);
windowVisibilityList[idx].overlapping = (rec.y < focusedRec.y+focusedRec.height-zoneReduction && rec.y+rec.height > focusedRec.y+zoneReduction);
let x2 = rec.x+rec.width;
rec.x = Math.max(rec.x, focusedRec.x+focusedRec.width+1);
rec.width = x2 - rec.x;
if (rec.width >= cornerAllowance && rec.height >= cornerAllowance) {
windowVisibilityList[idx].cornerVisibility = this.getCornerVisibility( windowVisibilityList[idx], windowList, rec.x+cornerAllowance, rec.x+rec.width-cornerAllowance, rec.y+cornerAllowance, rec.y+rec.height-cornerAllowance );
candidateList.push(windowVisibilityList[idx]);
}
}
} else if (direction == Direction.Up) {
if (rec.y < focusedRec.y) {
windowVisibilityList[idx].overlapping = (rec.x < focusedRec.x+focusedRec.width && rec.x+rec.width > focusedRec.x)
windowVisibilityList[idx].rec.height = Math.min(rec.height, focusedRec.y-1-rec.y);
windowVisibilityList[idx].cornerVisibility = this.getCornerVisibility( windowVisibilityList[idx], windowList, rec.x, rec.x+rec.width, rec.y, rec.y+rec.height );
candidateList.push(windowVisibilityList[idx]);
windowVisibilityList[idx].overlapping = (rec.x < focusedRec.x+focusedRec.width-zoneReduction && rec.x+rec.width > focusedRec.x+zoneReduction)
rec.height = Math.min(rec.height, focusedRec.y-1-rec.y);
if (rec.width >= cornerAllowance && rec.height >= cornerAllowance) {
windowVisibilityList[idx].cornerVisibility = this.getCornerVisibility( windowVisibilityList[idx], windowList, rec.x+cornerAllowance, rec.x+rec.width-cornerAllowance, rec.y+cornerAllowance, rec.y+rec.height-cornerAllowance );
candidateList.push(windowVisibilityList[idx]);
}
}
} else if (direction == Direction.Down) {
if (rec.y+rec.height > focusedRec.y+focusedRec.height) {
windowVisibilityList[idx].overlapping = (rec.x < focusedRec.x+focusedRec.width && rec.x+rec.width > focusedRec.x)
windowVisibilityList[idx].rec.y = Math.max(rec.y, focusedRec.y+focusedRec.height+1);
windowVisibilityList[idx].cornerVisibility = this.getCornerVisibility( windowVisibilityList[idx], windowList, rec.x, rec.x+rec.width, rec.y, rec.y+rec.height );
candidateList.push(windowVisibilityList[idx]);
windowVisibilityList[idx].overlapping = (rec.x < focusedRec.x+focusedRec.width-zoneReduction && rec.x+rec.width > focusedRec.x+zoneReduction)
let y2 = rec.y+rec.height;
rec.y = Math.max(rec.y, focusedRec.y+focusedRec.height+1);
rec.height = y2 - rec.y;
if (rec.width >= cornerAllowance && rec.height >= cornerAllowance) {
windowVisibilityList[idx].cornerVisibility = this.getCornerVisibility( windowVisibilityList[idx], windowList, rec.x+cornerAllowance, rec.x+rec.width-cornerAllowance, rec.y+cornerAllowance, rec.y+rec.height-cornerAllowance );
candidateList.push(windowVisibilityList[idx]);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@
"description": "Activate the window that is...",
"tooltip": "When using the Left, Right, Above or Below hotkeys, activate the window that is either:\n- Closest to the current window: this might activate a window that is currently completely obscured by other windows.\n- Highest in the z-order: most recently focused; this might skip over visible windows that are closer to the current window.\n- Closest window with a visible corner: a compromise that is designed to be more like what most people would generally expect (I hope)."
},
"overlap-allowance": {
"type": "spinbutton",
"default": 0,
"min": 0,
"max": 50,
"units": "pixels",
"step": 1,
"description": "Corner overlap allowance / minimum visibility",
"tooltip": "Sets how many pixels a corner can be obscured by other windows and still be considered a candidate window. Also sets the minimum amount of window visibility in order to qualify as a candidate window",
"dependency": "next-focus=2"
},
"boost-restriction": {
"type": "spinbutton",
"default": 0,
"min": 0,
"max": 85,
"units": "priority",
"step": 1,
"description": "Increase the priority of direction alignment",
"tooltip": "Increasing this setting gives more priority to windows that occupy the same area as the current window in the desired direction, and less priority to widows that are at an offset but closer. Max 85%",
"dependency": "next-focus=2"
},
"include-minimized": {
"type": "switch",
"default": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"uuid": "adjacent-windows@klangman",
"name": "Adjacent Windows",
"version": "1.0.0",
"version": "1.1.0",
"description": "Use hotkeys to switch to adjacent windows",
"url": "https://github.com/klangman/Adjacent-Windows",
"website": "https://github.com/klangman/Adjacent-Windows",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: adjacent-windows@klangman 1.0.0\n"
"Project-Id-Version: adjacent-windows@klangman 1.1.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-"
"extensions/issues\n"
"POT-Creation-Date: 2024-03-17 22:29-0400\n"
"POT-Creation-Date: 2024-03-25 21:17-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -25,63 +25,63 @@ msgstr ""
msgid "Use hotkeys to switch to adjacent windows"
msgstr ""

#. settings-schema.json->keybinding-header->description
#. 5.4->settings-schema.json->keybinding-header->description
msgid "Hotkeys to switch focus relative to the current window"
msgstr ""

#. settings-schema.json->left-key->description
#. 5.4->settings-schema.json->left-key->description
msgid "Activate window to the left"
msgstr ""

#. settings-schema.json->right-key->description
#. 5.4->settings-schema.json->right-key->description
msgid "Activate window to the right"
msgstr ""

#. settings-schema.json->up-key->description
#. 5.4->settings-schema.json->up-key->description
msgid "Activate window above"
msgstr ""

#. settings-schema.json->down-key->description
#. 5.4->settings-schema.json->down-key->description
msgid "Activate window below"
msgstr ""

#. settings-schema.json->under-key->description
#. 5.4->settings-schema.json->under-key->description
msgid "Activate window under"
msgstr ""

#. settings-schema.json->under-key->tooltip
#. 5.4->settings-schema.json->under-key->tooltip
msgid ""
"Switch to the next window in the z-order that is overlapped by the current "
"window. If the key combo is pressed again within 3 sec, the focus will "
"change to the next window beneath the window that originally had the focus "
"during the fist key combo press."
msgstr ""

#. settings-schema.json->back-key->description
#. 5.4->settings-schema.json->back-key->description
msgid "Undo the focus change"
msgstr ""

#. settings-schema.json->settings-header->description
#. 5.4->settings-schema.json->settings-header->description
msgid "Other settings"
msgstr ""

#. settings-schema.json->next-focus->options
#. 5.4->settings-schema.json->next-focus->options
msgid "Closest to the current window"
msgstr ""

#. settings-schema.json->next-focus->options
#. 5.4->settings-schema.json->next-focus->options
msgid "Highest in the z-order"
msgstr ""

#. settings-schema.json->next-focus->options
#. 5.4->settings-schema.json->next-focus->options
msgid "Closest with a visible corner"
msgstr ""

#. settings-schema.json->next-focus->description
#. 5.4->settings-schema.json->next-focus->description
msgid "Activate the window that is..."
msgstr ""

#. settings-schema.json->next-focus->tooltip
#. 5.4->settings-schema.json->next-focus->tooltip
msgid ""
"When using the Left, Right, Above or Below hotkeys, activate the window that "
"is either:\n"
Expand All @@ -93,10 +93,40 @@ msgid ""
"more like what most people would generally expect (I hope)."
msgstr ""

#. settings-schema.json->include-minimized->description
#. 5.4->settings-schema.json->overlap-allowance->units
msgid "pixels"
msgstr ""

#. 5.4->settings-schema.json->overlap-allowance->description
msgid "Corner overlap allowance / minimum visibility"
msgstr ""

#. 5.4->settings-schema.json->overlap-allowance->tooltip
msgid ""
"Sets how many pixels a corner can be obscured by other windows and still be "
"considered a candidate window. Also sets the minimum amount of window "
"visibility in order to qualify as a candidate window"
msgstr ""

#. 5.4->settings-schema.json->boost-restriction->units
msgid "priority"
msgstr ""

#. 5.4->settings-schema.json->boost-restriction->description
msgid "Increase the priority of direction alignment"
msgstr ""

#. 5.4->settings-schema.json->boost-restriction->tooltip
msgid ""
"Increasing this setting gives more priority to windows that occupy the same "
"area as the current window in the desired direction, and less priority to "
"widows that are at an offset but closer. Max 85%"
msgstr ""

#. 5.4->settings-schema.json->include-minimized->description
msgid "Allow switching to minimized windows"
msgstr ""

#. settings-schema.json->include-other-monitors->description
#. 5.4->settings-schema.json->include-other-monitors->description
msgid "Allow switching to windows on other monitors"
msgstr ""
64 changes: 47 additions & 17 deletions adjacent-windows@klangman/files/adjacent-windows@klangman/po/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: adjacent-windows@klangman 1.0.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-"
"extensions/issues\n"
"POT-Creation-Date: 2024-03-17 22:29-0400\n"
"POT-Creation-Date: 2024-03-25 21:17-0400\n"
"PO-Revision-Date: 2024-03-18 01:00-0300\n"
"Last-Translator: \n"
"Language-Team: \n"
Expand All @@ -25,32 +25,32 @@ msgstr "Ventanas adyacentes"
msgid "Use hotkeys to switch to adjacent windows"
msgstr "Utilice teclas de acceso rápido para cambiar a ventanas adyacentes"

#. settings-schema.json->keybinding-header->description
#. 5.4->settings-schema.json->keybinding-header->description
msgid "Hotkeys to switch focus relative to the current window"
msgstr ""
"Teclas de acceso rápido para cambiar el enfoque relativo a la ventana actual"

#. settings-schema.json->left-key->description
#. 5.4->settings-schema.json->left-key->description
msgid "Activate window to the left"
msgstr "Activar ventana a la izquierda"

#. settings-schema.json->right-key->description
#. 5.4->settings-schema.json->right-key->description
msgid "Activate window to the right"
msgstr "Activar ventana a la derecha"

#. settings-schema.json->up-key->description
#. 5.4->settings-schema.json->up-key->description
msgid "Activate window above"
msgstr "Activar la ventana de arriba"

#. settings-schema.json->down-key->description
#. 5.4->settings-schema.json->down-key->description
msgid "Activate window below"
msgstr "Activar la ventana de abajo"

#. settings-schema.json->under-key->description
#. 5.4->settings-schema.json->under-key->description
msgid "Activate window under"
msgstr "Activar ventana debajo"

#. settings-schema.json->under-key->tooltip
#. 5.4->settings-schema.json->under-key->tooltip
msgid ""
"Switch to the next window in the z-order that is overlapped by the current "
"window. If the key combo is pressed again within 3 sec, the focus will "
Expand All @@ -63,31 +63,31 @@ msgstr ""
"ventana que tenía el foco originalmente durante la primera pulsación de la "
"combinación de teclas."

#. settings-schema.json->back-key->description
#. 5.4->settings-schema.json->back-key->description
msgid "Undo the focus change"
msgstr "Deshacer el cambio de enfoque"

#. settings-schema.json->settings-header->description
#. 5.4->settings-schema.json->settings-header->description
msgid "Other settings"
msgstr "Otros ajustes"

#. settings-schema.json->next-focus->options
#. 5.4->settings-schema.json->next-focus->options
msgid "Closest to the current window"
msgstr "Más cerca de la ventana actual"

#. settings-schema.json->next-focus->options
#. 5.4->settings-schema.json->next-focus->options
msgid "Highest in the z-order"
msgstr "Más alta en el orden z"

#. settings-schema.json->next-focus->options
#. 5.4->settings-schema.json->next-focus->options
msgid "Closest with a visible corner"
msgstr "Más cercana con una esquina visible"

#. settings-schema.json->next-focus->description
#. 5.4->settings-schema.json->next-focus->description
msgid "Activate the window that is..."
msgstr "Active la ventana que está..."

#. settings-schema.json->next-focus->tooltip
#. 5.4->settings-schema.json->next-focus->tooltip
msgid ""
"When using the Left, Right, Above or Below hotkeys, activate the window that "
"is either:\n"
Expand All @@ -107,10 +107,40 @@ msgstr ""
"- Ventana más cercana con una esquina visible: un compromiso diseñado para "
"que se parezca más a lo que la mayoría de la gente esperaría (espero)."

#. settings-schema.json->include-minimized->description
#. 5.4->settings-schema.json->overlap-allowance->units
msgid "pixels"
msgstr ""

#. 5.4->settings-schema.json->overlap-allowance->description
msgid "Corner overlap allowance / minimum visibility"
msgstr ""

#. 5.4->settings-schema.json->overlap-allowance->tooltip
msgid ""
"Sets how many pixels a corner can be obscured by other windows and still be "
"considered a candidate window. Also sets the minimum amount of window "
"visibility in order to qualify as a candidate window"
msgstr ""

#. 5.4->settings-schema.json->boost-restriction->units
msgid "priority"
msgstr ""

#. 5.4->settings-schema.json->boost-restriction->description
msgid "Increase the priority of direction alignment"
msgstr ""

#. 5.4->settings-schema.json->boost-restriction->tooltip
msgid ""
"Increasing this setting gives more priority to windows that occupy the same "
"area as the current window in the desired direction, and less priority to "
"widows that are at an offset but closer. Max 85%"
msgstr ""

#. 5.4->settings-schema.json->include-minimized->description
msgid "Allow switching to minimized windows"
msgstr "Permitir el cambio a ventanas minimizadas"

#. settings-schema.json->include-other-monitors->description
#. 5.4->settings-schema.json->include-other-monitors->description
msgid "Allow switching to windows on other monitors"
msgstr "Permitir el cambio a ventanas de otros monitores"

0 comments on commit bc40b86

Please sign in to comment.