BelkaDev / KRunner-Joplin-plugin

A KDE runner to search, open and create notes in Joplin Desktop.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Send focus to client upon selection

EduPereyra opened this issue · comments

Hi, I'm trying this excellent plugin again. It's working correctly but the there's an error with xdotool while trying to get the focus of the client:
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Error: Command failed: xdotool windowactivate
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: There are no windows in the stack
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Invalid window '%1'
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Usage: windowactivate [options] [window=%1]
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: --sync - only exit once the window is active (is visible + active)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: If no window is given, %1 is used. See WINDOW STACK in xdotool(1)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at ChildProcess.exithandler (node:child_process:398:12)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at ChildProcess.emit (node:events:527:28)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at maybeClose (node:internal/child_process:1090:16)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at Socket. (node:internal/child_process:449:11)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at Socket.emit (node:events:527:28)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at Pipe. (node:net:709:12) {
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: code: 1,
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: killed: false,
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: signal: null,
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: cmd: 'xdotool windowactivate '
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: }
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: /home/deflex/.local/share/kservices5/joplin-runner/src/runner.js:14
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: : reject(new Error(${stderr} ${error}));
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: ^
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Error: There are no windows in the stack
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Invalid window '%1'
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Usage: windowactivate [options] [window=%1]
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: --sync - only exit once the window is active (is visible + active)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: If no window is given, %1 is used. See WINDOW STACK in xdotool(1)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Error: Command failed: xdotool windowactivate
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: There are no windows in the stack
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Invalid window '%1'
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Usage: windowactivate [options] [window=%1]
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: --sync - only exit once the window is active (is visible + active)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: If no window is given, %1 is used. See WINDOW STACK in xdotool(1)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at /home/deflex/.local/share/kservices5/joplin-runner/src/runner.js:14:15
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at ChildProcess.exithandler (node:child_process:406:5)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at ChildProcess.emit (node:events:527:28)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at maybeClose (node:internal/child_process:1090:16)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at Socket. (node:internal/child_process:449:11)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at Socket.emit (node:events:527:28)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: at Pipe. (node:net:709:12)
Mar 31 17:08:45 Pneuma net.belka.joplin[274339]: Node.js v17.8.0

So basically the plugin is working but it's not giving focus to joplin-desktop.

commented

Does this command work for you?

xdotool windowactivate $(xdotool search --onlyvisible --class joplin)

If not, I'm assuming the class name of your client could be different, so try out this command on Joplin

xprop WM_CLASS

Hi! the class name is correct . I just realized that sending focus to the client only works when the client is not minimized (I'm guessing because of the onlyvisible flag in xdotool).
Was this always the case? I've used your plugin in the past and I don´t recall if this was the general behavior.

commented

Did you change your WM or your panel layout?
Testing with Kwin and a Task manager should show the normal behavior.

As a workaround you can try this command

xdotool windowactivate $(xdotool search --class joplin | tail -n1)

But I can't guarantee it to work all the time because it assumes it's the last opened window in the stack

I'm using latte-dock right now, I guess I was using the regular kwin panel before when I used your plugin.
I'll try that workaround! Thanks!