Skip to content

Instantly share code, notes, and snippets.

@nolar
Created March 21, 2014 17:44
Show Gist options
  • Save nolar/9691610 to your computer and use it in GitHub Desktop.
Save nolar/9691610 to your computer and use it in GitHub Desktop.
--- WindowlistScreenlet.py.orig 2008-10-27 22:31:14.000000000 +0300
+++ WindowlistScreenlet.py 2008-10-27 23:52:14.000000000 +0300
@@ -28,6 +28,8 @@
import screenlets
from screenlets import DefaultMenuItem
from screenlets.options import BoolOption
+from screenlets.options import StringOption
+from screenlets.options import IntOption
import cairo
import gtk
import wnck
@@ -49,10 +51,10 @@
__open_tasks = []
__tooltips = None # tooltips object
__box = None # content gtk.Box (HBox/Vbox)
- vertical = False
- left = False
# TODO: make user-definable settings of these
- #direction = 1 # 1=right, 2=bottom (TODO)
+ orientation = False # ideally: 0 - horiz, 1 - vert
+ direction = "Middle" # ideally: 0 - middle, -1 - left/top, +1 - right/bottom
+ tasks_correction= 0
icon_size = 32
icon_spacing = 15
#shadow_offset = 3
@@ -65,7 +67,7 @@
# constructor
def __init__ (self, text="", **keyword_args):
#call super (and don't make this a "Widget")
- screenlets.Screenlet.__init__(self, width=40, height=40,
+ screenlets.Screenlet.__init__(self, width=self.icon_size, height=self.icon_size,
is_widget=False, is_sticky=True, **keyword_args)
# add HBox for children (TODO: optional: vbox)
@@ -80,12 +82,16 @@
"activation may not work"
self.add_options_group('Options', 'Options ...')
- self.add_option(BoolOption('Options','vertical',
- self.vertical, 'Expand Verticaly (restart req) ',
- 'Expand window list verticaly'))
- self.add_option(BoolOption('Options','left',
- self.left, 'Expand left (restart req)',
- 'Expand window list left'))
+ self.add_option(BoolOption('Options','orientation',
+ self.orientation, 'Vertical ',
+ 'Expand window list verticaly (check) or horizontally (unchecked).'))
+ self.add_option(StringOption('Options','direction',
+ self.direction, 'Direction for expansion',
+ 'Where to expand when new windows appear, relatively to orientation',
+ ["Back","Middle","Front"]))
+ self.add_option(IntOption('Options','tasks_correction',
+ self.tasks_correction, 'HIDDEN', 'HIDDEN',
+ hidden=True))
# connect screen-signal handlers
screen = wnck.screen_get_default()
self.__active_win = screen.get_active_window()
@@ -96,6 +102,7 @@
#screen.connect("application_opened", self.test_event)
# screen.connect("window_stacking_changed",
# self.window_stacking_changed)
+ # fixing last quit-position
# TEST: place in lower left (TODO: make this an option)
#self.__dict__['x'] = 20
#self.y = screen.get_height() - 50
@@ -113,7 +120,7 @@
# TODO: don't use only window names for this check
def on_init (self):
print "Screenlet has been initialized."
- if self.vertical == False:
+ if self.orientation == False:
self.__box = gtk.HBox()
else:
self.__box = gtk.VBox()
@@ -125,6 +132,19 @@
DefaultMenuItem.PROPERTIES |
DefaultMenuItem.DELETE | DefaultMenuItem.QUIT | DefaultMenuItem.QUIT_ALL)
+ # fixing position according to last width/height (tasks_correction)
+ if not self.orientation:
+ if self.direction == 'Back':
+ self.x = self.x + self.tasks_correction * (self.icon_size + self.icon_spacing)
+ if self.direction == 'Middle':
+ self.x = self.x + self.tasks_correction * (self.icon_size + self.icon_spacing) / 2
+ if self.orientation:
+ if self.direction == 'Back':
+ self.y = self.y + self.tasks_correction * (self.icon_size + self.icon_spacing)
+ if self.direction == 'Middle':
+ self.y = self.y + self.tasks_correction * (self.icon_size + self.icon_spacing) / 2
+ self.tasks_correction = 0
+
def check_window_name (self, name):
if name[-10:] != "Screenlets" and name[-12:] != "Screenlet.py" \
and name[-9:] != "Screenlet" and name != "Desktop":
@@ -174,6 +194,7 @@
self.__tooltips.set_tip(iw, wnckwin.get_name())
# add wnckwin/taskicon to open apps list
self.__open_tasks.append((wnckwin, iw ))
+ self.tasks_correction = len(self.__open_tasks)
# remove a task - removes TaskIconWidget
def remove_task (self, wnckwin):
@@ -185,6 +206,7 @@
break
if tsk:
self.__open_tasks.remove(t)
+ self.tasks_correction = len(self.__open_tasks)
return True
return False
@@ -263,20 +285,20 @@
# add new taskicon for the window
self.add_task(wnckwin)
# set size to correctly draw shape mask
- if self.vertical:
- self.height = len(self.__open_tasks) * (self.icon_size +
- self.icon_spacing)
- self.width = 40
- if self.left :
- self.y = self.y - (self.icon_size +
- self.icon_spacing)
+ if self.orientation:
+ self.height = len(self.__open_tasks) * (self.icon_size + self.icon_spacing)
+ self.width = self.icon_spacing
+ if self.direction == 'Back' :
+ self.y = self.y - (self.icon_size + self.icon_spacing)
+ if self.direction == 'Middle' :
+ self.y = self.y - (self.icon_size + self.icon_spacing) / 2
else:
- self.width = len(self.__open_tasks) * (self.icon_size +
- self.icon_spacing)
- self.height = 40
- if self.left and self.has_started and self.window.window.is_visible():
- self.x = self.x - (self.icon_size +
- self.icon_spacing)
+ self.width = len(self.__open_tasks) * (self.icon_size + self.icon_spacing)
+ self.height = self.icon_spacing
+ if self.direction == 'Back' and self.has_started and self.window.window.is_visible():
+ self.x = self.x - (self.icon_size + self.icon_spacing)
+ if self.direction == 'Middle' and self.has_started and self.window.window.is_visible():
+ self.x = self.x - (self.icon_size + self.icon_spacing) / 2
self.update_shape()
# called when a wnckwin is closed
@@ -284,26 +306,21 @@
#print "window_closed: "+str(window)
if self.remove_task(wnckwin):
# set size to correctly draw shape mask
- if self.vertical:
- self.height = len(self.__open_tasks) * (self.icon_size +
- self.icon_spacing)
- self.width = 40
- if self.left and self.has_started and self.window.window.is_visible():
- self.y = self.y + (self.icon_size +
- self.icon_spacing)
+ if self.orientation:
+ self.height = len(self.__open_tasks) * (self.icon_size + self.icon_spacing)
+ self.width = self.icon_size
+ if self.direction == 'Back' and self.has_started and self.window.window.is_visible():
+ self.y = self.y + (self.icon_size + self.icon_spacing)
+ if self.direction == 'Middle' and self.has_started and self.window.window.is_visible():
+ self.y = self.y + (self.icon_size + self.icon_spacing) / 2
else:
- self.width = len(self.__open_tasks) * (self.icon_size +
- self.icon_spacing)
- self.height = 40
- if self.left and self.has_started and self.window.window.is_visible():
- self.x = self.x + (self.icon_size +
- self.icon_spacing)
+ self.width = len(self.__open_tasks) * (self.icon_size + self.icon_spacing)
+ self.height = self.icon_size
+ if self.direction == 'Back' and self.has_started and self.window.window.is_visible():
+ self.x = self.x + (self.icon_size + self.icon_spacing)
+ if self.direction == 'Middle' and self.has_started and self.window.window.is_visible():
+ self.x = self.x + (self.icon_size + self.icon_spacing) / 2
self.update_shape()
- def on_quit(self):
- if self.left:
- if not self.vertical : self.x = self.x + self.width
- else:self.y = self.y + self.height
- print 'quiting'
# a window's state changed
def window_state_changed (self, wnckwin, changed, new_state):
#print "state_changed: "+str(new_state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment