3

Let's say I have applications A, B, C in the current workspace. A and B are beside each other (assume Application A is on focus) and C is not visible on the screen (it may [minimized] or [not be minimized, but it's not visible]) . I would like the program to print A, B and not C.

I tried using the Wnck package, but I only managed to get the following:

  1. Application in focus: screen.get_active_window().
  2. All applications in the workspace: screen.get_windows().

but I am not able to get the application only in the view of the user, i.e. A and B.

In summary, I want to print all applications in the view of the user (which is visible on the screen), irrespective of whether they are in focus or not.

user127167
  • 33
  • 3

1 Answers1

0

You could do something like this:

import gi
gi.require_version('Wnck', '3.0')
from gi.repository import Wnck

def get_winlist(): """ Get the window list and the active workspace. """ scr = Wnck.Screen.get_default() scr.force_update() windows = scr.get_windows() active_wspace = scr.get_active_workspace()

return windows, active_wspace

wlist, active_wspace = get_winlist()

for w in wlist: if w.is_visible_on_workspace(active_wspace): print(w.get_name())

I tweaked the code I found in this answer: How to determine if window is maximised or minimised from bash script

The get_winlist() function returns a list of all open windows and the current workspace. The code after it prints only the non-minimized windows of the current workspace.

  • it also prints those applications/windows where are not minimized and not visible to the user. i don't want it to print, the non-visible application, – user127167 Nov 08 '20 at 16:51
  • @user127167 I don't seem to be able to find an option to detect only visible windows in the Wnck API. Theoretically it should be possible to get the order and dimensions of all windows on the current workspace, compare them and come up with a list of visible windows. However, this is a lot of work and I am not really familiar with Wnck, so I won't be able to assist you further. I hope another user can help you more. – BeastOfCaerbannog Nov 08 '20 at 17:56