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.

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.