Python 3. Gtk 3. Wnck. How do I not show certain windows / programs?

Question:

How can wnck not show certain application windows? For example, I get a list of all open applications:

from gi.repository import Gtk, Wnck

Gtk.main_iteration()

screen = Wnck.Screen.get_default()
screen.force_update()
screen.get_windows()

Conclusion:

  Window object at 0x167bd20 (WnckWindow at 0x195d0e0),
  Window object at 0x167bf00 (WnckWindow at 0x195d740),
  Window object at 0x167bf50 (WnckWindow at 0x195d850)

For example, my application is called "SampleApp". How to get its identifier and hide it from the list?

Answer:

The get_windows () method returns a list of objects of type Wnck.Window ( https://lazka.github.io/pgi-docs/Wnck-3.0/classes/Screen.html#Wnck.Screen.get_windows) . Such objects have a get_name () method – https://lazka.github.io/pgi-docs/Wnck-3.0/classes/Window.html#Wnck.Window.get_name . Putting it all together, it turns out:

restricted_names = {"SampleApp", "SecondApp"}
windows = [wind for wind in screen.get_windows() if wind.get_name() not in restricted_names]
Scroll to Top