lxEdge positionne et redimensionne vos fenêtres
Rédigé par BeHuman
Aucun commentaire
Classé dans : Python

Je viens de me faire un petit script pour repositionner mes fenêtres sur ma session LXDE. Le but étant de pouvoir bouger une fenêtre à droite ou à gauche de l'écran et celle-ci se redimensionne et positionne automatiquement sur la moitié de l'écran (droite ou gauche).
Code Python
#!/usr/bin/env python
import sys, os, time, wnck, urllib, gtk
#threading
try:
from Xlib import X
import Xlib.display
r_screen = Xlib.display.Display().screen()
wnck_screen = wnck.screen_get_default()
wnck_screen.force_update()
except:
raise
#threading.Thread
class Hook():
def __init__(self, nom='', screen=r_screen):
#threading.Thread.__init__(self)
self.root_screen = screen
self.nom = nom
self.is_alive = True
def run(self):
self.root_win = self.root_screen.root.query_pointer()._data
self.root_win_x = self.root_win["root_x"]
self.root_win_y = self.root_win["root_y"]
self.root_mask = self.root_win["mask"]
return self.root_win_x, self.root_win_y, self.root_mask
#threading.Thread
class hotCorner():
def __init__(self, nom='', wnck_screen=wnck_screen, screen=r_screen):
#threading.Thread.__init__(self)
self.wnck_screen = wnck_screen
self.root_screen = screen
self.root_win = self.root_screen.root.get_geometry()._data
self.root_win_w = self.root_win["width"]
self.root_win_h = self.root_win["height"]
self.nom = nom
def run(self):
_iconify=1
old_x=0
old_y=0
hover=False
while True:
c = Hook('hook')
c.run()
time.sleep(0.01)
while gtk.events_pending():
gtk.main_iteration()
if c and hasattr(c, 'root_win_x') and hasattr(c, 'root_win_y'):
if c.root_win_x!=old_x and c.root_win_y!=old_y:
#print(c.root_win_x,old_x , c.root_win_y,old_y)
currentwindow = self.wnck_screen.get_active_window()
if type(currentwindow) is wnck.Window:
if c.root_mask>0:
hover=True
if hover and c.root_mask==0:
hover=False
if c.root_win_x <= 10 and c.root_win_y > 10 and c.root_win_y < self.root_win_h-10 : #gauche
print "Left Windows"
if currentwindow.is_maximized():
currentwindow.unmaximize()
currentwindow.set_geometry(0,1|2|4|8,-2,-4,self.root_win_w/2+1,self.root_win_h-24)
elif c.root_win_x <= 10 and c.root_win_y <= 10 : #topgauche
print "Top Left Windows"
if currentwindow.is_maximized():
currentwindow.unmaximize()
currentwindow.set_geometry(0,1|2|4|8,-2,-4,self.root_win_w/2+1,self.root_win_h/2)
elif c.root_win_x <= 10 and c.root_win_y >= self.root_win_h-10 : #bottom gauche
print "Bottom Left Windows"
if currentwindow.is_maximized():
currentwindow.unmaximize()
currentwindow.set_geometry(0,1|2|4|8,-2,self.root_win_h/2-4,self.root_win_w/2+1,self.root_win_h/2-24)
elif c.root_win_x+10 >= self.root_win_w and c.root_win_y > 10 and c.root_win_y < self.root_win_h-10: #droite
print "Right Windows"
if currentwindow.is_maximized():
currentwindow.unmaximize()
currentwindow.set_geometry(0,1|2|4|8,(self.root_win_w/2)-1,-4,self.root_win_w/2+1,self.root_win_h-24)
elif c.root_win_x+10 >= self.root_win_w and c.root_win_y <= 10 : #top droite
print "Top Right Windows"
if currentwindow.is_maximized():
currentwindow.unmaximize()
currentwindow.set_geometry(0,1|2|4|8,(self.root_win_w/2)-1,-4,self.root_win_w/2+1,self.root_win_h/2)
elif c.root_win_x+10 >= self.root_win_w and c.root_win_y >= self.root_win_h-10 : #bottom droite
print "Bottom Right Windows"
if currentwindow.is_maximized():
currentwindow.unmaximize()
currentwindow.set_geometry(0,1|2|4|8,(self.root_win_w/2)-1,self.root_win_h/2-4,self.root_win_w/2+1,self.root_win_h/2-24)
elif c.root_win_y <= 20 : #top
print "Maximize Windows"
currentwindow.set_geometry(0,1|2|4|8,(self.root_win_w/2)/2,(self.root_win_h/2)/2,self.root_win_w/2,self.root_win_h/2)
currentwindow.maximize()
old_x=c.root_win_x
old_y=c.root_win_y
th_hotcorner = hotCorner('hotcorner')
th_hotcorner.run()
#th_hotcorner.start()
#time.sleep(0.1)