emiapwil / glassy-gnome

To bring opacity features to gnome windows.
GNU General Public License v2.0
63 stars 9 forks source link

Hotkey to toggle glassy-gnome for some windows #5

Closed ipaq3870 closed 8 years ago

ipaq3870 commented 8 years ago

Hi,

I need to disable glassy for some windows on demand via hotkeys - like one non transparent Firefox window but the other Firefox windows remain glassy. I propose the following patch in the hope that it will be useful to someone else. It uses Supr-7 to toggle between enable/disable state.

--- extension.js.3  2016-04-18 16:56:56.764140355 +0800
+++ extension.js    2016-04-19 13:00:26.724875643 +0800
@@ -17,6 +17,7 @@
 const inc_key           = 'inc-opacity-key';
 const dec_key           = 'dec-opacity-key';
 const reset_key         = 'reset-opacity-key';
+const disable_key  = 'disable-opacity-key';

 var settings, filters, activated;

@@ -92,6 +93,9 @@
         return;
     }

+    if (!win.get_meta_window().glassy.enabled) {
+        opacity = 0;
+    }
     indicator.set_opacity(opacity);
 }

@@ -231,6 +235,22 @@
     glassify();
 }

+function disable_window_opacity() {
+    let win = get_active_window();
+    if (win != null) {
+        let meta_win = win.get_meta_window();
+        test_glassy_window(meta_win);
+
+        if (activated && meta_win.glassy.enabled) {
+            meta_win.glassy.enabled = false;
+        } else if (activated && !meta_win.glassy.enabled) {
+            meta_win.glassy.enabled = true;
+        }
+    }
+
+    glassify();
+}
+
 function _add_keybinding(key, func) {
     if (Main.wm.addKeybinding) {
         Main.wm.addKeybinding(key, settings, Meta.KeyBindingFlags.NONE,
@@ -255,6 +275,7 @@
     _add_keybinding(inc_key, increase_window_opacity);
     _add_keybinding(dec_key, decrease_window_opacity);
     _add_keybinding(reset_key, reset_window_opacity);
+    _add_keybinding(disable_key, disable_window_opacity);
 }

 function unbind_shortcuts() {
@@ -263,6 +284,7 @@
     _remove_keybinding(inc_key);
     _remove_keybinding(dec_key);
     _remove_keybinding(reset_key);
+    _remove_keybinding(disable_key);
 }

 function init() {
@@ -295,6 +317,7 @@
     setting_signals.push(settings.connect('changed::' + inc_key, update_settings));
     setting_signals.push(settings.connect('changed::' + dec_key, update_settings));
     setting_signals.push(settings.connect('changed::' + reset_key, update_settings));
+    setting_signals.push(settings.connect('changed::' + disable_key, update_settings));
 }

 function disconnect_signals() {
--- schemas/org.gnome.shell.extensions.glassy-gnome.gschema.xml.0   2015-08-28 14:32:04.000000000 +0800
+++ schemas/org.gnome.shell.extensions.glassy-gnome.gschema.xml 2016-04-19 12:30:19.038915689 +0800
@@ -46,6 +46,11 @@
             <summary>Shortcut to reset the opacity of the active window to default (the values in the filters).</summary>
         </key>

+        <key name="disable-opacity-key" type="as">
+            <default><![CDATA[['<Super>7']]]></default>
+            <summary>Shortcut to disable the opacity of the active window.</summary>
+        </key>
+
         <key name="auto-start" type="b">
             <default>true</default>
             <summary>Start Glassy GNOME when the system starts up.</summary>
emiapwil commented 8 years ago

Hello @ipaq3870, I believe this feature is already implemented.

Can you try the following command and see if it works?

gsettings --schemadir ~/.local/share/gnome-shell/extensions/glassygnome@emiapwil/schemas set org.gnome.shell.extensions.glassy-gnome toggle-glassy-window-key "['<Super>7']"