1 # vim:set et sts=4 sw=4:
5 # Copyright(c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
6 # Copyright(c) 2007-2010 Red Hat, Inc.
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
27 class Handle(gtk.EventBox):
28 __gtype_name__ = "IBusHandle"
31 gobject.SIGNAL_RUN_LAST,
35 gobject.SIGNAL_RUN_LAST,
41 super(Handle, self).__init__()
42 self.set_visible_window(False)
43 self.set_size_request(10, -1)
46 gdk.BUTTON_PRESS_MASK | \
47 gdk.BUTTON_RELEASE_MASK | \
48 gdk.BUTTON1_MOTION_MASK)
50 self.__move_begined = False
52 root = gdk.get_default_root_window()
54 def do_button_press_event(self, event):
56 root = gdk.get_default_root_window()
58 desktop = root.property_get("_NET_CURRENT_DESKTOP")[2][0]
59 self.__workarea = root.property_get("_NET_WORKAREA")[2][desktop * 4: (desktop + 1) * 4]
61 self.__workarea = None
62 self.__move_begined = True
63 toplevel = self.get_toplevel()
64 x, y = toplevel.get_position()
65 self.__press_pos = event.x_root - x, event.y_root - y
66 self.window.set_cursor(gdk.Cursor(gdk.FLEUR))
67 self.emit("move-begin")
71 def do_button_release_event(self, event):
73 self.__move_begined = False
76 self.window.set_cursor(gdk.Cursor(gdk.LEFT_PTR))
82 def do_motion_notify_event(self, event):
83 if not self.__move_begined:
85 toplevel = self.get_toplevel()
86 x, y = toplevel.get_position()
87 x = int(event.x_root - self.__press_pos[0])
88 y = int(event.y_root - self.__press_pos[1])
90 if self.__workarea == None:
94 if x < self.__workarea[0] and x > self.__workarea[0] - 16:
95 x = self.__workarea[0]
96 if y < self.__workarea[1] and y > self.__workarea[1] - 16:
97 y = self.__workarea[1]
99 w, h = toplevel.get_size()
100 if x + w > self.__workarea[0] + self.__workarea[2] and \
101 x + w < self.__workarea[0] + self.__workarea[2] + 16:
102 x = self.__workarea[0] + self.__workarea[2] - w
103 if y + h > self.__workarea[1] + self.__workarea[3] and \
104 y + h < self.__workarea[1] + self.__workarea[3] + 16:
105 y = self.__workarea[1] + self.__workarea[3] - h
109 def do_expose_event(self, event):
110 self.style.paint_handle(
117 self.allocation.x, self.allocation.y,
118 10, self.allocation.height,
119 gtk.ORIENTATION_VERTICAL)