Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Here's an initial example to get started:
"hide_keybind": "<super>n",
"bindings": [
{ "wmclass": "^Slack$", "keybind": "<super>i" },
{ "wmclass": "^kitty$", "keybind": "<super>Return" }
{ "wmclass": "^kitty$", "keybind": "<super>Return", "launch_cmd": "kitty" }
]
}
```
Expand All @@ -48,6 +48,7 @@ measure:
* `wmclass`: regex used to target a window based on its class
* `title`: regex used to target a window based on its title
* `keybind`: shortcut in `[<Modifiers>+]<keycode>` notation
* `launch_cmd`: optional command to run to launch the program if there are no windows open. can be ommitted.

> [!NOTE]
> You only need to specify `wmclass` _or_ `title`. Of the two, `wmclass` is
Expand Down
27 changes: 22 additions & 5 deletions extension.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Extension } from 'resource:///org/gnome/shell/extensions/extension.js';
import Config from './config.js';
import KeyBinder from './keybinder.js';
import Window from './window.js';
import { Extension } from "resource:///org/gnome/shell/extensions/extension.js";
import Gio from "gi://Gio";
import Config from "./config.js";
import KeyBinder from "./keybinder.js";
import Window from "./window.js";

export default class ScratchpadExtension extends Extension {
enable() {
Expand Down Expand Up @@ -30,7 +31,22 @@ export default class ScratchpadExtension extends Extension {
toggleWindow(binding) {
let win = Window.find(binding);

if (win === null) { return; }
if (!win) {
if (binding.launch_cmd && !this._launching) {
this._launching = true;
const cmd = binding.launch_cmd.split(' ');
try {
Gio.Subprocess.new(cmd, Gio.SubprocessFlags.NONE);
} catch (e) {
log(
`[gnome-scratchpad] failed to launch [cmd=${binding.launch_cmd}]: ${e.message}`)
} finally {
setTimeout(() => { this._launching = false; }, 1000);
}
}

return;
}

if (win.focused()) {
win.hide();
Expand All @@ -40,6 +56,7 @@ export default class ScratchpadExtension extends Extension {
}
}


hideWindows() {
for (const binding of this.config.bindings) {
Window.find(binding)?.hide();
Expand Down