Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| #!/usr/bin/env python2 | |
| # Sets panel to specified opacity depending on the visilibity of a maximized | |
| # window on the current workspace. Basically hacks together what wingpanel does. | |
| # You need xfce4-dockbarx-plugin >= 0.4 for this to work properly with it. | |
| # | |
| # Usage: xfce4-panel-fader panel# alpha_normal alpha_max | |
| # | |
| # by Trent "TiZ" McPheron. MIT/X11 License. | |
| import gtk | |
| import wnck | |
| import dbus | |
| from dbus.mainloop.glib import DBusGMainLoop | |
| import re | |
| rx = re.compile(r"^(/panels/panel-.+/)(?:alpha-(?:normal|max)|range-(?:x|y))$") | |
| class PanelFader: | |
| def __init__ (self): | |
| self.window = None | |
| self.state_handler = None | |
| self.wksp_handler = None | |
| self.bus = dbus.SessionBus() | |
| self.xfconf = dbus.Interface(self.bus.get_object( | |
| "org.xfce.Xfconf", "/org/xfce/Xfconf"), "org.xfce.Xfconf") | |
| self.panels = {panel: self.xfconf_get_panel(panel) for panel in set([ | |
| rx.sub(r"\1", prop) for prop in [ | |
| k for (k, v) in self.xfconf.GetAllProperties( | |
| "xfce4-panel", "/panels").iteritems() if rx.match(str(k)) | |
| ] | |
| ]) | |
| } | |
| self.bus.add_signal_receiver(self.xfconf_changed, "PropertyChanged", | |
| "org.xfce.Xfconf", "org.xfce.Xfconf", "/org/xfce/Xfconf") | |
| self.screen = wnck.screen_get_default() | |
| while gtk.events_pending(): | |
| gtk.main_iteration() | |
| self.screen.connect("active_window_changed", self.active_win_change) | |
| self.screen.connect("active_workspace_changed", self.check_status) | |
| self.screen.connect("window_opened", self.check_status) | |
| self.screen.connect("window_closed", self.check_status) | |
| self.active_win_change() | |
| # Xfconf stuff. | |
| def xfconf_get (self, prop_base, prop, default=None): | |
| if self.xfconf.PropertyExists("xfce4-panel", prop_base + prop): | |
| retval = self.xfconf.GetProperty("xfce4-panel", prop_base + prop) | |
| return retval | |
| else: | |
| return default | |
| def xfconf_get_panel (self, prop_base): | |
| panel = {} | |
| panel["base"] = prop_base | |
| panel["normal"] = self.xfconf_get(prop_base, "alpha-normal", 0) | |
| panel["max"] = self.xfconf_get(prop_base, "alpha-max", 100) | |
| panel["range_x"] = [int(x) for x in | |
| self.xfconf_get(prop_base, "range-x", [0, 9999])] | |
| if len(panel["range_x"]) != 2: panel["range_x"] = [0, 9999] | |
| panel["range_y"] = [int(x) for x in | |
| self.xfconf_get(prop_base, "range-y", [0, 9999])] | |
| if len(panel["range_y"]) != 2: panel["range_y"] = [0, 9999] | |
| return panel | |
| def xfconf_changed (self, channel, prop, val): | |
| if channel != "xfce4-panel" or not rx.match(prop): return | |
| panel = rx.sub(r"\1", prop) | |
| self.panels[panel] = self.xfconf_get_panel(panel) | |
| self.check_status() | |
| # Wnck stuff. | |
| def active_win_change (self, null1=None, null2=None): | |
| if self.window and self.state_handler and self.wksp_handler: | |
| self.window.disconnect(self.state_handler) | |
| self.window.disconnect(self.wksp_handler) | |
| self.window = self.screen.get_active_window() | |
| if self.window: | |
| self.state_handler = self.window.connect("state_changed", | |
| self.check_status) | |
| self.wksp_handler = self.window.connect("workspace_changed", | |
| self.check_status) | |
| self.check_status() | |
| def check_status (self, null1=None, null2=None, null3=None): | |
| for k, v in self.panels.iteritems(): | |
| if len(self.get_wins(v)) > 0: self.set_panel_alpha(v, "max") | |
| else: self.set_panel_alpha(v, "normal") | |
| def get_wins (self, panel): | |
| return [w for w in self.screen.get_windows_stacked() if | |
| w.is_visible_on_workspace(self.screen.get_active_workspace()) and | |
| w.is_maximized() and not w.is_skip_tasklist() and | |
| w.get_window_type() == 0 and self.window_in_range(w, panel)] | |
| def window_in_range (self, window, panel): | |
| geometry = window.get_geometry() | |
| return panel["range_x"][0] <= geometry[0] <= panel["range_x"][1] and \ | |
| panel["range_y"][0] <= geometry[0] <= panel["range_y"][1] | |
| def set_panel_alpha (self, panel, which): | |
| self.xfconf.SetProperty("xfce4-panel", panel["base"] + | |
| "background-alpha", panel[which]) | |
| if __name__ == '__main__': | |
| DBusGMainLoop(set_as_default=True) | |
| fader = PanelFader() | |
| gtk.main() |