Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Option: Prevent window snapping with Super key. #79

Merged
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
22 changes: 17 additions & 5 deletions src/extension/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,11 +351,16 @@ export default class App extends Extension {
const spanMultipleZones = this.canSpanMultipleZones();

const useModifier = getBoolSetting(SETTINGS.USE_MODIFIER);
const preventSnapping = getBoolSetting(SETTINGS.PREVENT_SNAPPING);
this.isGrabbing = true;

if (useModifier &&
!this.modifiersManager.isHolding(MODIFIERS_ENUM.CONTROL))
return;

if (preventSnapping &&
this.modifiersManager.isHolding(MODIFIERS_ENUM.SUPER))
return;

activeMonitors().forEach(m => {
this.tabManager[m.index]?.allow_multiple_zones_selection(spanMultipleZones);
Expand Down Expand Up @@ -398,7 +403,8 @@ export default class App extends Extension {
});
});

if (getBoolSetting(SETTINGS.USE_MODIFIER) || getBoolSetting(SETTINGS.SPAN_MULTIPLE_ZONES)) {
if (getBoolSetting(SETTINGS.USE_MODIFIER) || getBoolSetting(SETTINGS.SPAN_MULTIPLE_ZONES)
|| getBoolSetting(SETTINGS.PREVENT_SNAPPING)) {
// callback run when a modifier change state (e.g from not pressed to pressed)
this.modifiersManager.connect("changed", () => {
if (!this.isGrabbing) {
Expand All @@ -413,15 +419,21 @@ export default class App extends Extension {
});
}

if (!getBoolSetting(SETTINGS.USE_MODIFIER)) return;

if (this.modifiersManager.isHolding(MODIFIERS_ENUM.CONTROL)) {
const useModifier = getBoolSetting(SETTINGS.USE_MODIFIER);
if (useModifier && this.modifiersManager.isHolding(MODIFIERS_ENUM.CONTROL)) {
activeMonitors().forEach(m => {
this.tabManager[m.index]?.show()
});
} else {
activeMonitors().forEach(m => this.tabManager[m.index]?.hide());
return;
}

const preventSnapping = getBoolSetting(SETTINGS.PREVENT_SNAPPING);
if(preventSnapping && !this.modifiersManager.isHolding(MODIFIERS_ENUM.SUPER)) {
return
}

activeMonitors().forEach(m => this.tabManager[m.index]?.hide());
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/extension/modifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default class ModifiersManager {

this.modifiers = [];

for (let i = 0; i < 6; i++) {
for (let i = 0; i < 7; i++) {
if (this.state & 1 << i && MODIFIERS[i] !== undefined) {
this.modifiers.push(MODIFIERS[i]);
}
Expand Down
1 change: 1 addition & 0 deletions src/extension/prefs_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default class GSnapPreferences extends ExtensionPreferences {
const span_multiple_zones_check = this.add_check(group, SETTINGS.SPAN_MULTIPLE_ZONES,
"Hold ALT to span multiple zones",
"This feature is not supported if you have the \"Show tabs\" feature enabled");
this.add_check(group, SETTINGS.PREVENT_SNAPPING, "Hold Super to prevent snapping windows");

// disable "Span multiple zones" setting if "Show tabs" setting was already enabled
if (this.settings.get_boolean(SETTINGS.SHOW_TABS)) {
Expand Down
6 changes: 6 additions & 0 deletions src/extension/settings_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type BoolSettingName = (
"debug" |
"global-presets" |
"moveresize-enabled" |
"prevent-snapping" |
"show-icon" |
"show-tabs" |
"span-multiple-zones" |
Expand Down Expand Up @@ -115,6 +116,7 @@ export type AnySettingName = (
"preset-resize-7" |
"preset-resize-8" |
"preset-resize-9" |
"prevent-snapping" |
"show-icon" |
"show-tabs" |
"span-multiple-zones" |
Expand Down Expand Up @@ -260,6 +262,9 @@ export class ParsedSettings {
/** Preset resize 9. */
["preset-resize-9"]: string[] = ['<Super><Alt>KP_9'];

/** Hold Super to prevent snapping windows */
["prevent-snapping"]: boolean = false;

/** Show gSnap icon on a panel. */
["show-icon"]: boolean = true;

Expand Down Expand Up @@ -322,6 +327,7 @@ export const PRESET_RESIZE_6 = "preset-resize-6";
export const PRESET_RESIZE_7 = "preset-resize-7";
export const PRESET_RESIZE_8 = "preset-resize-8";
export const PRESET_RESIZE_9 = "preset-resize-9";
export const PREVENT_SNAPPING = "prevent-snapping";
export const SHOW_ICON = "show-icon";
export const SHOW_TABS = "show-tabs";
export const SPAN_MULTIPLE_ZONES = "span-multiple-zones";
Expand Down
Binary file modified src/schemas/gschemas.compiled
Binary file not shown.
4 changes: 4 additions & 0 deletions src/schemas/org.gnome.shell.extensions.gsnap.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@
<default>false</default>
<summary>Hold CTRL to snap windows</summary>
</key>
<key type = "b" name="prevent-snapping">
<default>false</default>
<summary>Hold Super to prevent snapping windows</summary>
</key>
<key type = "b" name="span-multiple-zones">
<default>false</default>
<summary>Hold ALT to span multiple zones</summary>
Expand Down