from i3pystatus.core import CommandEndpoint from i3pystatus.network import Network from i3pystatus.clock import Clock from gi.repository import Gtk import subprocess import sys import psutil import os import traceback ############################################################################### # Tools ############################################################################### g_i3bar_size = 20 def exec(s): p = subprocess.Popen(s.split(), stdout=sys.stderr.buffer) return p.pid def check_pid(pid): if psutil.pid_exists(pid): proc = psutil.Process(pid) if proc.status() == psutil.STATUS_ZOMBIE: os.kill(pid, 2) return False return True return False def get_current_screen_size(x, y): screen = Gtk.Window().get_screen() mn_number = screen.get_monitor_at_point(x, y) return screen.get_monitor_geometry(mn_number) ############################################################################### # Command end point ############################################################################### def change_command_end_point(): """ We create a modified version of _command_endpoint that add the support of x and y""" def _command_endpoint(self): for command in self.io_handler_factory().read(): target_module = self.modules.get(command["instance"]) if target_module: try: target_module._pos_x = int(command["x"]) target_module._pos_y = int(command["y"]) target_module.on_click(command["button"]) except Exception: continue CommandEndpoint._command_endpoint = _command_endpoint ############################################################################### # Clock ############################################################################### def change_clock(): def display_calendar(quit, s): if "_pid" in s.__dict__ and check_pid(s._pid): return x, y = s._pos_x, s._pos_y width_calendar, height_calendar = 300, 210 # fixed values... rect = get_current_screen_size(x, y) x = rect.width + rect.x - width_calendar if (y < g_i3bar_size): y = rect.y + g_i3bar_size else: y = rect.height + rect.y - height_calendar - g_i3bar_size s._pid = exec("calendar-window --size=%d-%d --position=%d-%d " "--onLostFocus=%s" % (width_calendar, height_calendar, x, y, "quit" if quit else "ignore")) def display_calendar_quit(s): display_calendar(True, s) def display_calendar_ignore(s): display_calendar(False, s) Clock.display_calendar_quit = display_calendar_quit Clock.display_calendar_ignore = display_calendar_ignore Clock.on_leftclick = "display_calendar_quit" Clock.on_rightclick = "display_calendar_ignore" ############################################################################### # Network ############################################################################### def change_network(): # We create the switch function def switch_hide(s): s.format_up, s.format_up_hide = s.format_up_hide, s.format_up s.format_down, s.format_down_hide = s.format_down_hide, s.format_down # We add it to the module Network.switch_hide = switch_hide # We add the correct settings and we init everything properly Network.format_up_hide = Network.format_up Network.format_down_hide = Network.format_down Network.on_leftclick = "switch_hide" Network.settings += (("format_down_hide", ""),) Network.settings += (("format_up_hide", ""),) # We change the mouse control Network.format_up_hide = Network.format_up Network.on_rightclick = Network.on_leftclick Network.on_upscroll = Network.on_leftclick Network.on_downscroll = Network.on_leftclick ############################################################################### # Change that we apply ############################################################################### def change_all(): change_command_end_point() change_clock() change_network()