More new API stuff

This commit is contained in:
K. Lange 2018-09-25 21:12:49 +09:00
parent 1050d76c87
commit fb067c4b93
7 changed files with 48 additions and 8 deletions

View File

@ -21,7 +21,7 @@ class AboutAppletWindow(yutani.Window):
text_offset = 110
def __init__(self, decorator, title, logo, text, icon="star",on_close=None):
super(AboutAppletWindow, self).__init__(self.base_width + decorator.width(), self.base_height + decorator.height(), title=title, icon=icon, doublebuffer=True)
super(AboutAppletWindow, self).__init__(self.base_width + decorator.width(), self.base_height + decorator.height(), title=title, flags=yutani.WindowFlag.FLAG_DISALLOW_RESIZE, icon=icon, doublebuffer=True)
self.move(int((yutani.yutani_ctx._ptr.contents.display_width-self.width)/2),int((yutani.yutani_ctx._ptr.contents.display_height-self.height)/2))
self.decorator = decorator
if logo.endswith('.png'):

View File

@ -201,9 +201,12 @@ class CalculatorWindow(yutani.Window):
self.flip()
def mouse_event(self, msg):
if d.handle_event(msg) == yutani.Decor.EVENT_CLOSE:
decor_event = d.handle_event(msg)
if decor_event == yutani.Decor.EVENT_CLOSE:
window.close()
sys.exit(0)
elif decor_event == yutani.Decor.EVENT_RIGHT:
d.show_menu(self, msg)
x,y = msg.new_x - self.decorator.left_width(self), msg.new_y - self.decorator.top_height(self)
w,h = self.width - self.decorator.width(self), self.height - self.decorator.height(self)

View File

@ -121,12 +121,15 @@ class DialogWindow(yutani.Window):
self.flip()
def mouse_event(self, msg):
if self.decorator.handle_event(msg) == yutani.Decor.EVENT_CLOSE:
decor_event = self.decorator.handle_event(msg)
if decor_event == yutani.Decor.EVENT_CLOSE:
if self.close_is_cancel:
self.cancel_click(None)
else:
self.ok_click(None)
return
elif decor_event == yutani.Decor.EVENT_RIGHT:
self.decorator.show_menu(self, msg)
x,y = msg.new_x - self.decorator.left_width(), msg.new_y - self.decorator.top_height()
w,h = self.width - self.decorator.width(), self.height - self.decorator.height()

View File

@ -242,9 +242,12 @@ class FileBrowserWindow(yutani.Window):
self.scroll_y = -100 * rows
def mouse_event(self, msg):
if d.handle_event(msg) == yutani.Decor.EVENT_CLOSE:
decor_event = d.handle_event(msg)
if decor_event == yutani.Decor.EVENT_CLOSE:
window.close()
sys.exit(0)
elif decor_event == yutani.Decor.EVENT_RIGHT:
d.show_menu(self, msg)
x,y = msg.new_x - self.decorator.left_width(self), msg.new_y - self.decorator.top_height(self)
w,h = self.width - self.decorator.width(self), self.height - self.decorator.height(self)

View File

@ -294,9 +294,12 @@ class MinesWindow(yutani.Window):
self.flip()
def mouse_event(self, msg):
if d.handle_event(msg) == yutani.Decor.EVENT_CLOSE:
decor_event = d.handle_event(msg)
if decor_event == yutani.Decor.EVENT_CLOSE:
window.close()
sys.exit(0)
elif decor_event == yutani.Decor.EVENT_RIGHT:
d.show_menu(self, msg)
x,y = msg.new_x - self.decorator.left_width(), msg.new_y - self.decorator.top_height()
w,h = self.width - self.decorator.width(), self.height - self.decorator.height()

View File

@ -10,6 +10,7 @@ import importlib
yutani_lib = None
yutani_gfx_lib = None
yutani_ctx = None
yutani_menu_lib = None
yutani_windows = {}
_cairo_lib = None
@ -329,16 +330,22 @@ class Yutani(object):
global yutani_lib
global yutani_ctx
global yutani_gfx_lib
global yutani_menu_lib
if not yutani_lib:
yutani_lib = CDLL("libtoaru_yutani.so")
if not yutani_gfx_lib:
yutani_gfx_lib = CDLL("libtoaru_graphics.so")
if not yutani_menu_lib:
yutani_menu_lib = CDLL("libtoaru_menu.so")
self._ptr = cast(yutani_lib.yutani_init(), POINTER(self._yutani_t))
if not self._ptr:
raise ConnectionRefusedError("Could not connect to compositor.")
yutani_ctx = self
self._fileno = _libc.fileno(self._ptr.contents.sock)
def process_menus(self, event):
return yutani_menu_lib.menu_process_event(self._ptr, event._ptr)
def poll(self, sync=True):
"""Poll for an event message."""
if sync:
@ -533,6 +540,11 @@ class Window(object):
("bufid", c_uint32),
("focused", c_uint8),
("oldbufid", c_uint32),
("userdata", c_void_p),
("x", c_int32),
("y", c_int32),
("decorator_flags", c_uint32),
("ctx", c_void_p),
]
class _gfx_context_t(Structure):
@ -668,6 +680,14 @@ class Window(object):
"""Begin window drag."""
yutani_lib.yutani_window_drag_start(yutani_ctx._ptr, self._ptr)
@property
def x(self):
return self._ptr.contents.x
@property
def y(self):
return self._ptr.contents.y
@property
def width(self):
return self._ptr.contents.width
@ -698,6 +718,8 @@ class Decor(object):
EVENT_OTHER = 1
EVENT_CLOSE = 2
EVENT_RESIZE = 3
EVENT_MAXIMIZE = 4
EVENT_RIGHT = 5
class decor_bound(Structure):
_fields_ = [
@ -764,6 +786,9 @@ class Decor(object):
"""Let the decorator library handle an event. Usually passed mouse events."""
return self.lib.decor_handle_event(yutani_ctx._ptr, msg._ptr)
def show_menu(self, window, event):
self.lib.decor_show_default_menu(window._ptr, window.x + event.new_x, window.y + event.new_y)
# Demo follows.
if __name__ == '__main__':
# Connect to the server.

View File

@ -5,6 +5,12 @@ def handle_event(msg):
if msg.type == yutani.Message.MSG_SESSION_END:
msg.free()
return False
elif msg.type == yutani.Message.MSG_WINDOW_CLOSE:
# TODO should actually send a close signal to the window
msg.free()
return False
elif yutani.yutani_ctx.process_menus(msg):
return True
elif msg.type == yutani.Message.MSG_KEY_EVENT:
if msg.wid in yutani.yutani_windows:
yutani.yutani_windows[msg.wid].keyboard_event(msg)
@ -33,9 +39,6 @@ def handle_event(msg):
window = yutani.yutani_windows[msg.wid]
if 'window_moved' in dir(window):
window.window_moved(msg)
else:
window.x = msg.x
window.y = msg.y
elif msg.type == yutani.Message.MSG_WINDOW_MOUSE_EVENT:
if msg.wid in yutani.yutani_windows:
window = yutani.yutani_windows[msg.wid]