How to handle keyboard events in gnome shell extensions?
I came across this snippet in gcampax's gtk-js-app template some time ago, which may be related to what you're doing:
// Due to limitations of gobject-introspection wrt GdkEvent and GdkEventKey,
// this needs to be a signal handler
this.connect('key-press-event', Lang.bind(this, this._handleKeyPress));
and
_handleKeyPress: function(self, event) {
return this.main_search_bar.handle_event(event);
},
I haven't had a need to use keyboard events yet, and this is Gtk in GJS, but the same limitation may be affecting gnome-shell extensions.
UPDATE
I've been doing some keybinding stuff lately, and if attaching a signal handler to the global object is working, you can do something like this:
global.display.connect("key-press-event", (widget, event, user_data) => {
let [success, keyval] = event.get_keyval(); // integer
let keyname = Gdk.keyval_name(keyval); // string keyname
if (keyname === "Control_L") {
// Dialog code or eg. this.keys_array.push("<Ctrl>");
}
});
There's also some Shell keybinding code here and some shell-global documentation here that might give you more clues. Wish I could help more but I'm wrestling my own GJS atm ;)
ADDENDUM
There is a good answer here with an example class with informative logging, as well as a speculative explanation. I've also found this functionality is exposed over DBus which might be more convenient in some cases:
Bus Name: org.gnome.Shell
-> Path: /org/gnome/Shell
-> Interface: org.gnome.Shell
Relevant Methods:
GrabAccelerator(String accelerator, UInt32 flags)
->(UInt32 action)
UngrabAccelerator(UInt32 action)
->(Boolean success)
Signal:
AcceleratorActivate(UInt32, Dict of {String, Variant})
In Gnome (gnome-shell) can you set multiple shortcut keys instead of just a single?
Yes, you can. This is verified to work on Ubuntu 20.10 and 21.04RC.
The following commands acheive the requested outcome:
gsettings set org.gnome.desktop.wm.keybindings switch-windows-backward "['<Shift><Super>Tab', '<Shift><Alt>Tab']"
gsettings set org.gnome.desktop.wm.keybindings switch-windows "['<Super>Tab', '<Alt>Tab']"
For more options see here:
# list all keybindings
gsettings list-recursively | grep -e org.gnome.desktop.wm.keybindings -e org.gnome.settings-daemon.plugins.media-keys -e org.gnome.settings-daemon.plugins.power | sort
# confirm no other keybinding conflicts
gsettings list-recursively | grep '<Control>1'
# set multiple keybindings for "Switch to Workspace 1"
gsettings set org.gnome.desktop.wm.keybindings switch-to-workspace-1 "['<Super>Home', '<Control>1']"
# confirm value is set correctly
gsettings get org.gnome.desktop.wm.keybindings switch-to-workspace-1
from here.
Create a GNOME shell extension that enables and disables the webcam
You should probably start by looking through the tutorial on the GNOME Wiki:
https://wiki.gnome.org/Projects/GnomeShell/Extensions/Writing
When spawning your command, you're probably going to want to use pkexec
instead of sudo
. I wouldn't recommend doing anything requiring superuser access in an extension, but pkexec
will at least work properly in a GUI environment.
To spawn your command, you can probably get away with GLib.spawn_command_line_async()
, although I always prefer GSubprocess
myself.
gnome-shell-extensions Not able to upload the complete directory
These files must be in the top-level of the Zip:
metadata.json
extension.js
prefs.js
(Optional file)stylesheet.css
(Optional file)
That is the only requirement. The -r
and -j
functions are explained by zip --help
:
-j junk (don't record) directory names
-r recurse into directories
If all your extension files are in one, top-level directory then -j
will work, otherwise it will probably break your directory hierarchy. You can check the layout of a zip with unzip -l
.
Typically you will zip with zip -r extension@domain.zip [path with metadata.json]
:
$ ls
extensions.js metadata.json
$ zip -r extension@domain.zip .
adding: metadata.json (deflated 33%)
adding: extension.js (deflated 55%)
$ unzip -l extension@domain.zip
Archive: extension@domain.zip
Length Date Time Name
--------- ---------- ----- ----
194 04-25-2020 17:47 metadata.json
864 04-25-2020 17:47 extension.js
--------- -------
1058 2 files
Related Topics
Install Python 32 Bit on 64 Bit Linux
Docker Can't Write to Directory Mounted Using -V Unless It Has 777 Permissions
How to Play an Audio File from Haskell Code, Cross-Platform
Bash Cut Columns to One File and Save onto The End of Another File
Where M Flag and O Flag Will Be Stored in Linux
How to Clear Docker Task History
Terraform - Unable to Run Multiple Commands in Local Exec
Process Niceness (Priority) Setting Has No Effect on Linux
Why Can't I Install Any Packages with Ghc 7.8.4 on Raspberry Pi
Git Error: Cannot Handle Https
How to Compile Redis So That I Can Upload and Run It on Shared Hosting
Apache 2.4.23 Undefined Reference to Crypto_Malloc_Init
How to Handle Error/Exception in Shell Script
Qt Does Not Create Output Files in Debug/Release Folders in Linux
Qt - How to Detect Whether The Application Is Running on Gnome or Kde