kazysmaster / gnome-shell-extension-lockkeys

Numlock and Capslock indicator for gnome-shell
168 stars 48 forks source link

Support for GNOME 40 #91

Closed drjhe closed 3 years ago

drjhe commented 3 years ago

The panel elements work OK just by adding "40" to the shell-version list in metadata.json, but it looks like the GTK+4 API has changed enough that the settings box won't work without some adjustment.

Below is the patch I used to get Lock Keys working on GNOME 40, but it's a bit crude and I don't really know how to do this elegantly in a way that works both on GNOME Shell 3.38 and 40 (hence why I refrained from making a pull request at this stage).

diff --git a/lockkeys@vaina.lt/metadata.json b/lockkeys@vaina.lt/metadata.json
index dfdb59d..713f7f8 100644
--- a/lockkeys@vaina.lt/metadata.json
+++ b/lockkeys@vaina.lt/metadata.json
@@ -1,5 +1,6 @@
 {
-   "shell-version": ["3.18", "3.20", "3.22", "3.24", "3.26", "3.28", "3.30", "3.32", "3.34", "3.36", "3.38"],
+   "shell-version": ["3.18", "3.20", "3.22", "3.24", "3.26", "3.28", "3.30",
+    "3.32", "3.34", "3.36", "3.38", "40"],
    "uuid": "lockkeys@vaina.lt", 
    "name": "Lock Keys", 
    "description": "Numlock & Capslock status on the panel", 
diff --git a/lockkeys@vaina.lt/prefs.js b/lockkeys@vaina.lt/prefs.js
index bfa2262..a516bd4 100644
--- a/lockkeys@vaina.lt/prefs.js
+++ b/lockkeys@vaina.lt/prefs.js
@@ -27,11 +27,11 @@ function init() {
 }

 function buildPrefsWidget() {
-   let frame = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL,
-       border_width: 10, margin: 20});
+   let frame = new Gtk.Box({orientation: Gtk.Orientation.VERTICAL, spacing: 10,
+       margin_top: 20, margin_start: 20});
    frame.set_spacing(10);

-   frame.add(_createComboBox(STYLE, _("Indicator Style"), _("Change indicator display options"), {
+   frame.append(_createComboBox(STYLE, _("Indicator Style"), _("Change indicator display options"), {
        [STYLE_NONE]: _("Notifications Only"),
        [STYLE_NUMLOCK_ONLY]: _("Num-Lock Only"),
        [STYLE_CAPSLOCK_ONLY]: _("Caps-Lock Only"),
@@ -39,13 +39,13 @@ function buildPrefsWidget() {
        [STYLE_SHOWHIDE]: _("Show/Hide")
    }));

-   frame.add(_createComboBox(NOTIFICATIONS, _("Notifications"), _("Show notifications when state changes"), {
+   frame.append(_createComboBox(NOTIFICATIONS, _("Notifications"), _("Show notifications when state changes"), {
        [NOTIFICATIONS_OFF]: _("Off"), 
        [NOTIFICATIONS_ON]: _("Compact"), 
        [NOTIFICATIONS_OSD]: _("Osd")
    }));

-   frame.show_all();
+   frame.show();
    return frame;
 }

@@ -57,8 +57,8 @@ function _createCheckBox(key, text, tooltip) {
        settings.set_boolean(key, switch_widget.active);
    });

-   box.pack_start(label, true, true, 0);
-   box.add(widget);
+   box.append(label, true, true, 0);
+   box.append(widget);
    return box;
 }

@@ -74,7 +74,7 @@ function _createComboBox(key, text, tooltip, values)
    widget.connect('changed', function(combo_widget) {
        settings.set_string(key, combo_widget.get_active_id());
    });
-   box.pack_start(label, true, true, 0);
-   box.add(widget);
+   box.append(label, true, true, 0);
+   box.append(widget);
    return box;
-}
\ No newline at end of file
+}
kazysmaster commented 3 years ago

Thanks, I will look into this when get on gnome 40 testing.

yochananmarqos commented 3 years ago

@drjhe I tried applying as a patch, but it failed:

patching file lockkeys@vaina.lt/metadata.json
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file lockkeys@vaina.lt/metadata.json.rej
patching file lockkeys@vaina.lt/prefs.js
Hunk #2 FAILED at 39.
1 out of 4 hunks FAILED -- saving rejects to file lockkeys@vaina.lt/prefs.js.rej

metadata.json.rej

--- lockkeys@vaina.lt/metadata.json
+++ lockkeys@vaina.lt/metadata.json
@@ -1,5 +1,6 @@
 {
-   "shell-version": ["3.18", "3.20", "3.22", "3.24", "3.26", "3.28", "3.30", "3.32", "3.34", "3.36", "3.38"],
+   "shell-version": ["3.18", "3.20", "3.22", "3.24", "3.26", "3.28", "3.30",
+    "3.32", "3.34", "3.36", "3.38", "40"],
    "uuid": "lockkeys@vaina.lt",
    "name": "Lock Keys",
    "description": "Numlock & Capslock status on the panel",

prefs.js.rej:

--- lockkeys@vaina.lt/prefs.js
+++ lockkeys@vaina.lt/prefs.js
@@ -39,13 +39,13 @@ function buildPrefsWidget() {
        [STYLE_SHOWHIDE]: _("Show/Hide")
    }));

-   frame.add(_createComboBox(NOTIFICATIONS, _("Notifications"), _("Show notifications when state changes"), {
+   frame.append(_createComboBox(NOTIFICATIONS, _("Notifications"), _("Show notifications when state changes"), {
        [NOTIFICATIONS_OFF]: _("Off"),
        [NOTIFICATIONS_ON]: _("Compact"),
        [NOTIFICATIONS_OSD]: _("Osd")
    }));

-   frame.show_all();
+   frame.show();
    return frame;
 }
drjhe commented 3 years ago

@drjhe I tried applying as a patch, but it failed:

That's strange. It applied cleanly for me to the current master, d7140aa. I copied and pasted the patch listing into a file, changed directory to my local clone of this repo, and applied it using patch -p1 < the.patch.

kazysmaster commented 3 years ago

please check out the master branch

kazysmaster commented 3 years ago

New version has been submitted for a review.