[kupfer: 31/67] ui: Allow Kupfer be run with undecorated, rounded Window



commit e9a33862dddd083d419b994d5332672a34f6f00e
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Wed Mar 16 22:49:01 2011 +0100

    ui: Allow Kupfer be run with undecorated, rounded Window
    
    Disabled by default(!) (Needs some kind of border/window edge).
    Implementation of round corners by Florian Apolloner
    
    Launchpad-bug: https://bugs.launchpad.net/kupfer/+bug/696727

 kupfer/ui/browser.py |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/ui/browser.py b/kupfer/ui/browser.py
index 07333fe..746bd70 100644
--- a/kupfer/ui/browser.py
+++ b/kupfer/ui/browser.py
@@ -1,6 +1,7 @@
 # -*- coding: UTF-8 -*-
 
 import itertools
+import math
 import os
 import signal
 import sys
@@ -14,6 +15,7 @@ except ImportError:
 import gtk
 import gio
 import gobject
+import cairo
 
 from kupfer import kupferui
 from kupfer import version
@@ -1476,6 +1478,7 @@ class WindowController (pretty.OutputMixin):
 		"""
 		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
 		self.window.add_events(gtk.gdk.BUTTON_PRESS_MASK)
+		self._use_window_decorations = True
 
 		data_controller = data.DataController()
 		data_controller.connect("launched-action", self.launch_callback)
@@ -1566,6 +1569,7 @@ class WindowController (pretty.OutputMixin):
 
 		self.window.connect("delete-event", self._close_window)
 		self.window.connect("focus-out-event", self._lost_focus)
+		self.window.connect("size-allocate", self._size_allocate)
 		widget = self.interface.get_widget()
 		widget.show()
 
@@ -1575,6 +1579,9 @@ class WindowController (pretty.OutputMixin):
 		self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_UTILITY)
 		self.window.set_property("skip-taskbar-hint", True)
 		self.window.set_keep_above(True)
+		if not self._use_window_decorations:
+			self.window.set_property("border-width", 8)
+			self.window.set_decorated(False)
 		if not text_direction_is_ltr():
 			self.window.set_gravity(gtk.gdk.GRAVITY_NORTH_EAST)
 		# Setting not resizable changes from utility window
@@ -1597,6 +1604,36 @@ class WindowController (pretty.OutputMixin):
 	def result_callback(self, sender, result_type):
 		self.activate()
 
+	def _size_allocate(self, win, allocation):
+		if self._use_window_decorations:
+			return
+		w,h = allocation.width, allocation.height
+		bitmap = gtk.gdk.Pixmap(None, w, h, 1)
+		cr = bitmap.cairo_create()
+
+		cr.set_source_rgb(0.0, 0.0, 0.0)
+		cr.set_operator(cairo.OPERATOR_CLEAR)
+		cr.paint()
+
+		# radius of rounded corner
+		arc_sz = 10
+		cr.set_source_rgb(1.0, 1.0, 1.0)
+		cr.set_operator(cairo.OPERATOR_SOURCE)
+		cr.move_to(arc_sz, 0)
+		cr.line_to(w-arc_sz,0)
+		cr.arc(w-arc_sz, arc_sz, arc_sz, 3/2*math.pi, 2*math.pi)
+		cr.line_to(w, h-arc_sz)
+		cr.arc(w-arc_sz, h-arc_sz, arc_sz, 0, math.pi/2)
+		cr.line_to(arc_sz, h)
+		cr.arc(arc_sz, h-arc_sz, arc_sz, math.pi/2, math.pi)
+		cr.line_to(0, arc_sz)
+		cr.arc(arc_sz, arc_sz, arc_sz, math.pi, math.pi/2)
+		cr.close_path()
+		cr.fill()
+
+		win.shape_combine_mask(bitmap, 0, 0)
+
+
 	def _lost_focus(self, window, event):
 		setctl = settings.GetSettingsController()
 		if setctl.get_close_on_unfocus():



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]