Xfce Forum

Sub domains
 

You are not logged in.

#1 2024-08-19 19:51:38

jyoung
Member
Registered: 2017-08-11
Posts: 31

[SOLVED] workspace from process id?

Given the process ID of a graphical application, is there a way to determine (from the command line) which workspace its window is in? Or, is there a way to query workspaces to see what windows they have open, and which process IDs are associated with those windows?

Last edited by jyoung (2024-08-21 21:17:16)

Offline

#2 2024-08-19 21:08:25

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,482

Re: [SOLVED] workspace from process id?

wmctrl -lvp

The second field is the workspace number. "-1" means the window is stickied and appears on all workspaces. Workspace numbering starts at 0. The third field is the pid.

You can parse out information from the results of that command as needed.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2024-08-19 21:40:17

ajgringo619
Member
Registered: 2024-06-09
Posts: 3

Re: [SOLVED] workspace from process id?

ToZ wrote:
wmctrl -lvp

The second field is the workspace number. "-1" means the window is stickied and appears on all workspaces. Workspace numbering starts at 0. The third field is the pid.

You can parse out information from the results of that command as needed.

While this works if the launched programs are unique, you can run into duplicate PIDs. For example, I run a couple of terminals in different workspaces, all showing the same PID from the aforementioned command:

$ wmctrl -lvp
envir_utf8: 1
0x00e00003 -1 1406   dss-endeavouros xfce4-panel
0x00e0000a -1 1406   dss-endeavouros xfce4-panel
0x02400003  0 1434   dss-endeavouros Terminal - fish [~]
0x00e00019 -1 1406   dss-endeavouros xfce4-panel
0x00e0001d -1 1406   dss-endeavouros xfce4-panel
0x00e00022 -1 1406   dss-endeavouros xfce4-panel
0x01200007 -1 1417   dss-endeavouros Desktop
0x02400026  2 1434   dss-endeavouros Terminal - fish [~]
0x02400162  2 1434   dss-endeavouros System Monitor

Even in this example, a terminal window with a different title ("System Monitor") shows the same PID as the other 2 terminals.

Offline

#4 2024-08-19 22:59:46

jyoung
Member
Registered: 2017-08-11
Posts: 31

Re: [SOLVED] workspace from process id?

ToZ, that's a really powerful command! Reading the man page, it does what I was looking for and a lost more.

ajgringo619, that's a good point. In the case of your terminal, I'm guessing that launching a "new" terminal just creates a new window for an existing terminal process, yes? I've noticed a similar pattern with a lot of graphical applications. My question here is actually aimed to subverting this behavior with gedit, but only in cases where the new instance is in a separate workspace.

Offline

#5 2024-08-19 23:02:50

ajgringo619
Member
Registered: 2024-06-09
Posts: 3

Re: [SOLVED] workspace from process id?

jyoung wrote:

ToZ, that's a really powerful command! Reading the man page, it does what I was looking for and a lost more.

ajgringo619, that's a good point. In the case of your terminal, I'm guessing that launching a "new" terminal just creates a new window for an existing terminal process, yes? I've noticed a similar pattern with a lot of graphical applications. My question here is actually aimed to subverting this behavior with gedit, but only in cases where the new instance is in a separate workspace.

I haven't tried any other terminal programs, so I'm not sure if this is exclusive to Xfce. When I create new terminals with a script, I make sure that the window titles are unique so moving them between workspaces or just finding them is simple.

Offline

#6 2024-09-10 00:12:50

Skaperen
Member
From: right by Jesus, our Saviour
Registered: 2013-06-15
Posts: 862

Re: [SOLVED] workspace from process id?

what if a process has no window but does have a controlling tty paired with a pty open by xfce4terminal that shows in that list.  i wrote a Python script i called ws that, with no argument, outputs the current workspace number being viewed via xfce4terminal, and, with a number, switches the view to that workspace.  i'm looking at adding more capability such as outputting the workspace it is in, and switching the view to itself.  all this would be through xfce4terminal since it would not know how to track through other kinds of open windows, besides possibly mapping process IDs and which workspace their window is in (unless they have windows open in multiple workspaces.

and no, i have not figured out how to open a window in a workspace no currently being viewed.

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.010 seconds, 7 queries executed - Memory usage: 536.99 KiB (Peak: 537.84 KiB) ]