Skip to content

Commit

Permalink
Gio instead of misc/util spawnCommandLine fix #70
Browse files Browse the repository at this point in the history
  • Loading branch information
e3rd committed Dec 20, 2023
1 parent e6d8521 commit 56aba26
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 33
- Gio instead of misc/util spawnCommandLine #70 (syslog cleaned up)

## 32
- raise-or-register with index #61

Expand Down
38 changes: 24 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ Several years ago, OS creators finally realized that efficiency and let the user

With the emergence of Wayland over X.org, we can't reliably use good old [`xbindkeys`](https://wiki.archlinux.org/index.php/Xbindkeys) and [`jumpapp`](https://github.com/mkropat/jumpapp) to master shortcuts. Here is a gnome-shell extension that let you migrate your favourite shortcuts to the `shortcuts.conf` file.

## Barebones “GNOME Shell native” alternative

Note that GNOME Shell supports a _basic_ run-or-raise workflow out of the box! In case this extension is broken or you cannot / don’t want to use it,

1. Pin your favorite apps to the Dash (`Activities``Right click` on open app → `Pin to Dash`)
2. Don’t let the default <kbd><Super+N></kbd> bindings cause you a left thumb [RSI](https://en.wikipedia.org/wiki/Repetitive_strain_injury)! To re-bind them, set dconf values `org.gnome.shell.keybindings` / `switch-to-application-N` to your desired keyboard shortcut (where N is 1..9), replacing / adding to the default binding.
3. Never re-order your pinned apps!
4. Enjoy a basic run-or-raise in Shell with no extension

Caveats:

- Limited to 9 apps! Choose wisely 😄.
- No wmclass regex support; limited to static `StartupWMClass` in XDG `.desktop` files
- No [run-or-raise "Modes"](#modes)
# Contents
- [Installation](#installation)
- [Configuration](#configuration)
* [How to create a shortcut](#how-to-create-a-shortcut)
+ [Shortcut](#shortcut)
+ [Action: `command`, `wm_class` and `title`](#action-command-wm_class-and-title)
- [Understanding `title` and `wm_class`](#understanding-title-and-wm_class)
- [Comparison of different matching approaches](#comparison-of-different-matching-approaches)
+ [Modes](#modes)
* [Examples](#examples)
- [Tips](#tips)
* [Barebones “GNOME Shell native” alternative](#barebones-gnome-shell-native-alternative)
* [Developer guide](#developer-guide)
+ [Debugging](#debugging)

# Installation

Expand Down Expand Up @@ -263,6 +263,16 @@ To run a command as a sudo, try simple `pkexec` program that raises the password
* You may change the configuration file on the fly. Just disable & enable the extension, shortcuts load again from scratch. Ex: `gnome-extensions disable run-or-raise@edvard.cz && gnome-extensions enable run-or-raise@edvard.cz`
* In the case of segfault, check no conflicting key binding [is present](https://github.com/CZ-NIC/run-or-raise/pull/1#issuecomment-350951994), then submit an issue.

## Barebones “GNOME Shell native” alternative

Note that GNOME Shell supports a _basic_ run-or-raise workflow out of the box! To enjoy a basic run-or-raise with no extension:

1. Pin your favorite apps to the Dash (`Activities``Right click` on open app → `Pin to Dash`).
2. Don’t let the default <kbd><Super+number></kbd> bindings cause you a left thumb [RSI](https://en.wikipedia.org/wiki/Repetitive_strain_injury)! To re-bind them, set dconf values `org.gnome.shell.keybindings` / `switch-to-application-N` to your desired keyboard shortcut (where N is 1..9), replacing / adding to the default binding.
3. Never re-order your pinned apps.

Caveats: Limited to 9 apps; no wmclass regex support; limited to static `StartupWMClass` in XDG `.desktop` files; no [modes](#modes).

## Developer guide

How to implement a new mode?
Expand Down
14 changes: 8 additions & 6 deletions lib/action.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Shell from 'gi://Shell';
import { spawnCommandLine } from 'resource:///org/gnome/shell/misc/util.js';
import {Mode} from './mode.js';
import { Mode } from './mode.js';
import Gio from 'gi://Gio';
import GLib from 'gi://GLib';

class Action {

Expand Down Expand Up @@ -219,11 +220,12 @@ class Action {
if (this.mode.get(Mode.VERBOSE)) {
this.debug("running:", this.command)
}
const app = Shell.AppSystem.get_default().lookup_app(this.command);
const app = Shell.AppSystem.get_default().lookup_app(this.command)
if (app !== null) {
return app.activate();
return app.activate()
}
return spawnCommandLine(this.command);
const [, argv] = GLib.shell_parse_argv(this.command)
return Gio.Subprocess.new(argv, Gio.SubprocessFlags.NONE)
}

/**
Expand Down Expand Up @@ -281,7 +283,7 @@ class Action {

}

export function parseLine(line, app) {
export function parseLine(line, app) {
// Optional argument quoting in the format: `shortcut[:mode][:mode],[command],[wm_class],[title]`
// ', b, c, "d, e,\" " f", g, h' -> ["", "b", "c", "d, e,\" \" f", "g", "h"]
const args = line.split(/,(?![^"]*"(?:(?:[^"]*"){2})*[^"]*$)/)
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
],
"url": "https://github.com/CZ-NIC/run-or-raise",
"uuid": "run-or-raise@edvard.cz",
"version": 32
"version": 33
}

0 comments on commit 56aba26

Please sign in to comment.