Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace switching under Compiz #1834

Open
dermidgen opened this issue Mar 4, 2021 · 0 comments
Open

Workspace switching under Compiz #1834

dermidgen opened this issue Mar 4, 2021 · 0 comments

Comments

@dermidgen
Copy link
Contributor

Similar to #1690

When running Ubuntu MATE with Compiz enabled, possibly depending on your Compiz settings, Desktops/Workspaces are reduced to 1 gigantic Desktop/Worspace/ViewPort and implements Virtual Desktops by moving the ViewPort. To effectively track "Workspace" switches you actually need to watch for the viewports-changed signal.

The EWMH library offers just a wee bit of extended information over Wnck, specifically:

  • getDesktopViewPort() which gives you the current X, Y of the ViewPort
  • getWorkArea() which gives you the actual width/height of the visible desktop area
  • getDesktopGeometry() which gives you the entire size of the gigantic desktop

Using these values, we can determine how many virtual workspaces there are - and which one we're on.

For example:

#!/usr/bin/env python3

from ewmh import EWMH
import gi
gi.require_version('Wnck', '3.0')
gi.require_version('Notify', '0.7')
from gi.repository import Wnck, Gtk, Notify
import signal, time

class SigWn:
   def __init__(self):
       signal.signal(signal.SIGINT, signal.SIG_DFL)
       Notify.init("Workspace Switch Notifier")
       self.screen = Wnck.Screen.get_default()
       self.ewmh = EWMH()
       self.desktop_width = self.ewmh.getWorkArea()[2]
       self.total_width = self.ewmh.getDesktopGeometry()[0]
       self.desktops = int(self.total_width / self.desktop_width)

   def on_change(self, window):
       current_desktop = int(self.ewmh.getDesktopViewPort()[0] / self.desktop_width) + 1
       popup = Notify.Notification.new(f'Desktop: {current_desktop} / {self.desktops}')
       popup.show()
       time.sleep(1)
       popup.close()

   def main(self):
       self.screen.connect("viewports-changed", self.on_change)
       Gtk.main()

if __name__ == '__main__':
   app = SigWn()
   app.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants