Skip to content

Commit 8181f2a

Browse files
authored
Merge pull request #88 from nlpsuge/dev-gnome41-compatibility
Gnome 41 compatibility. Related to #79. This might fix all issues mentioned in #79.
2 parents 17d4fd9 + da45800 commit 8181f2a

8 files changed

Lines changed: 75 additions & 63 deletions

File tree

closeSession.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,12 @@ var CloseSession = class {
391391
Log.Log.getDefault().debug(`Finished to start ydotool.service. Started: ${started}`);
392392
resolve(started);
393393
} catch (error) {
394+
const additionalInfo = 'Please make sure `ydotool` is installed and set up properly, see https://github.com/nlpsuge/gnome-shell-extension-another-window-session-manager#how-to-make-close-by-rules-work for more instruction';
394395
const msg = 'Failed to start ydotool.service';
395-
Log.Log.getDefault().error(error, msg);
396-
global.notify_error(`${msg}`, `${error ? error.message : ''}`);
397-
reject(false);
396+
Log.Log.getDefault().error(error, `${msg} ${additionalInfo}`);
397+
global.notify_error(`${msg}`, `${error ? error.message : ''} ${additionalInfo}`);
398+
// `ydotool` might not be available, which can't stop AWSM continue to close the rest of apps
399+
resolve(false);
398400
}
399401
});
400402
});
@@ -405,7 +407,7 @@ var CloseSession = class {
405407

406408
_getRunningAppsClosingByRules() {
407409
if (!this._settings.get_boolean('enable-close-by-rules')) {
408-
return [[], this._defaultAppSystem.get_running()];
410+
return [this._defaultAppSystem.get_running(), [], []];
409411
}
410412

411413
const closeWindowsRules = this._prefsUtils.getSettingString('close-windows-rules');

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
],
1212
"url": "https://github.com/nlpsuge/gnome-shell-extension-another-window-session-manager",
1313
"uuid": "another-window-session-manager@gmail.com",
14-
"version": 40
14+
"version": 41
1515
}

model/closeWindowsRule.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
const { GObject } = imports.gi;
44

5+
const ExtensionUtils = imports.misc.extensionUtils;
6+
const Me = ExtensionUtils.getCurrentExtension();
7+
const CloseWindowsRule = Me.imports.model.closeWindowsRule;
58

69
var CloseWindowsWhitelist = GObject.registerClass({
710
}, class CloseWindowsWhitelist extends GObject.Object {
@@ -14,7 +17,7 @@ var CloseWindowsWhitelist = GObject.registerClass({
1417
enableWhenLogout; // boolean
1518

1619
static new(param) {
17-
return Object.assign(new CloseWindowsWhitelist(), param);
20+
return Object.assign(new CloseWindowsRule.CloseWindowsWhitelist(), param);
1821
}
1922
});
2023

@@ -36,7 +39,7 @@ var CloseWindowsRuleByKeyword = class extends CloseWindowsRuleBase {
3639
method; // string. endsWith, includes, startsWith, equals, regex.
3740

3841
static new(param) {
39-
return Object.assign(new CloseWindowsRuleByKeyword(), param);
42+
return Object.assign(new CloseWindowsRule.CloseWindowsRuleByKeyword(), param);
4043
}
4144
}
4245

@@ -46,7 +49,7 @@ var CloseWindowsRuleByApp = class extends CloseWindowsRuleBase {
4649
appName; // string, such as 'Firefox'
4750

4851
static new(param) {
49-
return Object.assign(new CloseWindowsRuleByApp(), param);
52+
return Object.assign(new CloseWindowsRule.CloseWindowsRuleByApp(), param);
5053
}
5154
}
5255

@@ -83,6 +86,6 @@ var GdkShortcuts = GObject.registerClass({
8386
shiftRightPressed;
8487

8588
static new(param) {
86-
return Object.assign(new GdkShortcuts(), param);
89+
return Object.assign(new CloseWindowsRule.GdkShortcuts(), param);
8790
}
8891
});

prefs.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const Me = ExtensionUtils.getCurrentExtension();
66

77
const FileUtils = Me.imports.utils.fileUtils;
88
const Log = Me.imports.utils.log;
9+
const GnomeVersion = Me.imports.utils.gnomeVersion;
910

1011
Me.imports.utils.string;
1112

@@ -296,6 +297,17 @@ const BuilderScope = GObject.registerClass({
296297

297298
function buildPrefsWidget() {
298299
const settings = new Prefs();
300+
301+
if (GnomeVersion.isLessThan42()) {
302+
const scroll = new Gtk.ScrolledWindow({
303+
vexpand: true,
304+
hexpand: true,
305+
hscrollbar_policy: Gtk.PolicyType.NEVER,
306+
vscrollbar_policy: Gtk.PolicyType.AUTOMATIC
307+
});
308+
scroll.set_child(settings.notebook);
309+
return scroll;
310+
}
299311
return settings.notebook;
300312
}
301313

prefsCloseWindow.js

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ var UICloseWindows = GObject.registerClass(
4141
}
4242

4343
init() {
44-
const close_by_rules_multi_grid2 = this._builder.get_object('close_by_rules_multi_grid2');
45-
const close_by_rules_list_box = this._builder.get_object('close_by_rules_list_box');
46-
// Remove GtkScrolledWindow on Gnome 42
47-
// See: https://gjs.guide/extensions/upgrading/gnome-shell-42.html#gtk-scrolledwindow
48-
if (!GnomeVersion.isLessThan42()) {
49-
close_by_rules_list_box.unparent();
50-
close_by_rules_multi_grid2.attach(close_by_rules_list_box, 0, 0, 1, 1);
51-
}
52-
5344
this._initAppRules();
5445
this._initKeywordRules();
5546
this._initWhitelist();
@@ -111,7 +102,7 @@ var UICloseWindows = GObject.registerClass(
111102
}
112103

113104
_initAppRules() {
114-
const close_by_rules_list_box = this._builder.get_object('close_by_rules_list_box');
105+
const close_by_rules_list_box = this._builder.get_object('close_by_rules_applications_list_box');
115106
close_by_rules_list_box.set_header_func((currentRow, beforeRow, data) => {
116107
this._setHeader(currentRow, beforeRow, data, 'Applications');
117108
});
@@ -144,13 +135,7 @@ var UICloseWindows = GObject.registerClass(
144135
}
145136

146137
_initKeywordRules() {
147-
const close_by_rules_multi_grid2 = this._builder.get_object('close_by_rules_multi_grid2');
148-
const close_by_rules_by_keyword_list_box = new Gtk.ListBox({
149-
hexpand: true,
150-
vexpand: true,
151-
show_separators: true,
152-
});
153-
close_by_rules_multi_grid2.attach(close_by_rules_by_keyword_list_box, 0, 1, 1, 1);
138+
const close_by_rules_by_keyword_list_box = this._builder.get_object('close_by_rules_keywords_list_box');
154139
close_by_rules_by_keyword_list_box.set_header_func((currentRow, beforeRow, data) => {
155140
this._setHeader(currentRow, beforeRow, data, 'Keywords');
156141
});

ui/autoclose.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -483,12 +483,16 @@ var RunningApplicationListWindow = GObject.registerClass({
483483
}
484484

485485
_setInitialKeyFocus(actor) {
486-
this._initialKeyFocus?.disconnectObject(this);
486+
if (this._initialKeyFocus && this._initialKeyFocusDestroyId) {
487+
this._initialKeyFocus.disconnect(this._initialKeyFocusDestroyId);
488+
}
487489

488490
this._initialKeyFocus = actor;
489491

490-
actor.connectObject('destroy',
491-
() => (this._initialKeyFocus = null), this);
492+
this._initialKeyFocusDestroyId = actor.connect('destroy', () => {
493+
this._initialKeyFocus = null;
494+
this._initialKeyFocusDestroyId = 0;
495+
});
492496
}
493497

494498
open() {

ui/prefs-gtk4.ui

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -147,40 +147,33 @@
147147
</object>
148148
</child>
149149
<child>
150-
<object class="GtkGrid" id="close_by_rules_multi_grid2">
151-
<property name="margin-top">12</property>
152-
<property name="margin-bottom">12</property>
153-
<property name="row-spacing">6</property>
154-
<property name="column-spacing">32</property>
150+
<object class="GtkBox">
151+
<property name="orientation">vertical</property>
155152
<child>
156-
<object class="GtkScrolledWindow" id="close_rule_listbox_scrolledwindow">
157-
<property name="focusable">1</property>
158-
<property name="child">
159-
<object class="GtkViewport" id="close_rule_listbox_viewport">
160-
<property name="child">
161-
<object class="GtkListBox" id="close_by_rules_list_box">
162-
<property name="hexpand">True</property>
163-
<property name="vexpand">True</property>
164-
<property name="show-separators">True</property>
165-
166-
</object>
167-
</property>
168-
</object>
169-
</property>
170-
<layout>
171-
<property name="column">0</property>
172-
<property name="row">1</property>
173-
</layout>
153+
<object class="GtkListBox" id="close_by_rules_applications_list_box">
154+
<property name="hexpand">True</property>
155+
<property name="vexpand">True</property>
156+
<property name="show-separators">True</property>
157+
</object>
158+
</child>
159+
<child>
160+
<object class="GtkListBox" id="close_by_rules_keywords_list_box">
161+
<property name="hexpand">True</property>
162+
<property name="vexpand">True</property>
163+
<property name="show-separators">True</property>
164+
</object>
165+
</child>
166+
<child>
167+
<object class="GtkListBox" id="close_windows_whitelist_listbox">
168+
<property name="hexpand">True</property>
169+
<property name="vexpand">True</property>
170+
<property name="show-separators">True</property>
171+
<child>
172+
</child>
174173
</object>
175174
</child>
176175
</object>
177176
</child>
178-
<child>
179-
<object class="GtkListBox" id="close_windows_whitelist_listbox">
180-
<child>
181-
</child>
182-
</object>
183-
</child>
184177
</object>
185178
</property>
186179
<property name="tab">

utils/WindowPicker.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const Main = imports.ui.main;
1111
const LookingGlass = imports.ui.lookingGlass;
1212
const Me = imports.misc.extensionUtils.getCurrentExtension();
1313

14+
const GnomeVersion = Me.imports.utils.gnomeVersion;
15+
16+
1417
// Based on the WindowPicker.js from Burn-My-Windows.
1518
// I modified and enhanced it, so it can be used in my case
1619
// properly for the Another Window Session Manager extension.
@@ -46,9 +49,14 @@ var WindowPickerServiceProvider = class WindowPickerServiceProvider {
4649

4750
const inspector = new MyInspector(Main.createLookingGlass());
4851

52+
// Compatibility: gnome shell 41.x does not have the variable `_grab` in lookingGlass.LookingGlass
4953
// Release the global grab, so that we can move around freely (specially, free to use Ctrl+`
5054
// to switch windows) and pick a window that is on another workspace.
51-
Main.popModal(lookingGlass._grab);
55+
if (GnomeVersion.isLessThan42()) {
56+
// Main.popModal(lookingGlass._entry);
57+
} else {
58+
Main.popModal(lookingGlass._grab);
59+
}
5260

5361
inspector.connect('target', (me, target, x, y) => {
5462
// Remove border effect when window is picked.
@@ -91,11 +99,16 @@ var WindowPickerServiceProvider = class WindowPickerServiceProvider {
9199
this._dbus.emit_signal('WindowPicked', variant);
92100
});
93101

94-
// Close LookingGlass when we're done.
102+
// Close LookingGlass and release the grab when the picking is finished.
95103
inspector.connect('closed', () => {
96-
// Restore the global grab to prevent the error 'incorrect pop' thrown by LookingGlass.close/Main.popModal(this._grab)
97-
lookingGlass._grab = Main.pushModal(lookingGlass, { actionMode: Shell.ActionMode.LOOKING_GLASS });
98-
lookingGlass.close();
104+
if (GnomeVersion.isLessThan42()) {
105+
// Main.pushModal(lookingGlass._entry, { actionMode: Shell.ActionMode.LOOKING_GLASS });
106+
lookingGlass.close();
107+
} else {
108+
// Restore the global grab to prevent the error 'incorrect pop' thrown by LookingGlass.close/Main.popModal(this._grab)
109+
lookingGlass._grab = Main.pushModal(lookingGlass, { actionMode: Shell.ActionMode.LOOKING_GLASS });
110+
lookingGlass.close();
111+
}
99112
});
100113

101114
inspector.connect('WindowPickCancelled', () => {

0 commit comments

Comments
 (0)