3
# Copyright 2010 Google Inc.
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
9
# http://www.apache.org/licenses/LICENSE-2.0
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
17
"""Create a shaped window to show mouse events.
19
Thanks to mathias.gumz for the original code.
24
import lazy_pixbuf_creator
26
class ShapedWindow(gtk.Window):
27
"""Create a window shaped as fname."""
28
def __init__(self, fname, scale=1.0):
29
gtk.Window.__init__(self)
30
self.connect('size-allocate', self._on_size_allocate)
31
self.set_decorated(False)
32
self.set_keep_above(True)
38
self.pixbufs = lazy_pixbuf_creator.LazyPixbufCreator(self.name_fnames,
40
self.pixbuf = self.pixbufs.get('mouse')
41
self.resize(self.pixbuf.get_width(), self.pixbuf.get_height())
43
# a pixmap widget to contain the pixmap
44
self.image = gtk.Image()
45
bitmap, self.mask = self.pixbuf.render_pixmap_and_mask()
46
self.image.set_from_pixmap(bitmap, self.mask)
50
def _on_size_allocate(self, win, unused_allocation):
51
"""Called when first allocated."""
52
# Set the window shape
53
win.shape_combine_mask(self.mask, 0, 0)
54
win.set_property('skip-taskbar-hint', True)
55
if not win.is_composited():
56
print 'Unable to fade the window'
60
def center_on_cursor(self):
61
root = gtk.gdk.screen_get_default().get_root_window()
62
x, y, _ = root.get_pointer()
63
w, h = self.get_size()
64
new_x, new_y = x - w/2, y - h/2
65
pos = self.get_position()
66
if pos[0] != new_x or pos[1] != new_y:
67
self.move(new_x, new_y)
78
"""Make the window fade in a little bit."""
80
gobject.timeout_add(200, self.hide)