5 # Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this program; if not, write to the
19 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 # Boston, MA 02111-1307 USA
26 class Handle (gtk
.EventBox
):
28 gtk
.EventBox
.__init
__ (self
)
29 self
.set_visible_window (False)
30 self
.set_size_request (10, -1)
33 gdk
.BUTTON_PRESS_MASK | \
34 gdk
.BUTTON_RELEASE_MASK | \
35 gdk
.BUTTON1_MOTION_MASK
)
37 self
._move
_begined
= False
39 root
= gdk
.get_default_root_window ()
40 workarea
= root
.property_get ("_NET_WORKAREA")[2]
42 def do_button_press_event (self
, event
):
44 root
= gdk
.get_default_root_window ()
45 desktop
= root
.property_get ("_NET_CURRENT_DESKTOP")[2][0]
46 self
._workarea
= root
.property_get ("_NET_WORKAREA")[2][desktop
* 4: (desktop
+ 1) * 4]
47 self
._move
_begined
= True
48 toplevel
= self
.get_toplevel ()
49 x
, y
= toplevel
.get_position ()
50 self
._press
_pos
= event
.x_root
- x
, event
.y_root
- y
51 self
.window
.set_cursor (gdk
.Cursor (gdk
.FLEUR
))
55 def do_button_release_event (self
, event
):
57 self
._move
_begined
= False
60 self
.window
.set_cursor (gdk
.Cursor (gdk
.LEFT_PTR
))
65 def do_motion_notify_event (self
, event
):
66 if not self
._move
_begined
:
68 toplevel
= self
.get_toplevel ()
69 x
, y
= toplevel
.get_position ()
70 x
= int (event
.x_root
- self
._press
_pos
[0])
71 y
= int (event
.y_root
- self
._press
_pos
[1])
73 if x
< self
._workarea
[0] and x
> self
._workarea
[0] - 16:
75 if y
< self
._workarea
[1] and y
> self
._workarea
[1] - 16:
78 w
, h
= toplevel
.get_size ()
79 if x
+ w
> self
._workarea
[0] + self
._workarea
[2] and \
80 x
+ w
< self
._workarea
[0] + self
._workarea
[2] + 16:
81 x
= self
._workarea
[0] + self
._workarea
[2] - w
82 if y
+ h
> self
._workarea
[1] + self
._workarea
[3] and \
83 y
+ h
< self
._workarea
[1] + self
._workarea
[3] + 16:
84 y
= self
._workarea
[1] + self
._workarea
[3] - h
88 def do_expose_event (self
, event
):
89 self
.style
.paint_handle (
96 self
.allocation
.x
, self
.allocation
.y
,
97 10, self
.allocation
.height
,
98 gtk
.ORIENTATION_VERTICAL
)
101 gobject
.type_register (Handle
, "IBusHandle")