From 058302102380dc4e55624b0e4f29e2bae91b39cd Mon Sep 17 00:00:00 2001 From: Michael Webster Date: Tue, 5 Mar 2013 21:56:17 -0500 Subject: [PATCH] Add ctypes call for window tracking --- usr/lib/linuxmint/mintMenu/capi.py | 36 ++++++++++++++++++++++++++ usr/lib/linuxmint/mintMenu/mintMenu.py | 22 +++++----------- 2 files changed, 43 insertions(+), 15 deletions(-) create mode 100644 usr/lib/linuxmint/mintMenu/capi.py diff --git a/usr/lib/linuxmint/mintMenu/capi.py b/usr/lib/linuxmint/mintMenu/capi.py new file mode 100644 index 0000000..f947996 --- /dev/null +++ b/usr/lib/linuxmint/mintMenu/capi.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import gi +import ctypes +from ctypes import * + +libgobject = CDLL('libgobject-2.0.so.0') + +class _PyGObject_Functions(ctypes.Structure): + _fields_ = [ + ('register_class', + ctypes.PYFUNCTYPE(ctypes.c_void_p, ctypes.c_char_p, + ctypes.c_int, ctypes.py_object, + ctypes.py_object)), + ('register_wrapper', + ctypes.PYFUNCTYPE(ctypes.c_void_p, ctypes.py_object)), + ('lookup_class', + ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_int)), + ('newgobj', + ctypes.PYFUNCTYPE(ctypes.py_object, ctypes.c_void_p)), + ] + +class PyGObjectCPAI(object): + def __init__(self): + PyCObject_AsVoidPtr = ctypes.pythonapi.PyCObject_AsVoidPtr + PyCObject_AsVoidPtr.restype = ctypes.c_void_p + PyCObject_AsVoidPtr.argtypes = [ctypes.py_object] + addr = PyCObject_AsVoidPtr(ctypes.py_object( + gi._gobject._PyGObject_API)) + self._api = _PyGObject_Functions.from_address(addr) + + def pygobject_new(self, addr): + return self._api.newgobj(addr) + +def get_widget(ptr): + return PyGObjectCPAI().pygobject_new(ptr) diff --git a/usr/lib/linuxmint/mintMenu/mintMenu.py b/usr/lib/linuxmint/mintMenu/mintMenu.py index a929932..76b5759 100755 --- a/usr/lib/linuxmint/mintMenu/mintMenu.py +++ b/usr/lib/linuxmint/mintMenu/mintMenu.py @@ -16,11 +16,17 @@ try: import traceback import time import gc + import ctypes + from ctypes import * + import capi import xdg.Config except Exception, e: print e sys.exit( 1 ) +gtk = CDLL("libgtk-x11-2.0.so.0") +gdk = CDLL("libgdk-x11-2.0.so.0") + global mbindkey # Load the key binding lib (developped by deskbar-applet, copied into mintMenu so we don't end up with an unnecessary dependency) try: @@ -489,26 +495,12 @@ class MainWindow( object ): # Check if the pointer is within the menu, else hide the menu winatptr = Gdk.window_at_pointer() - widget_win = widget.get_window() - - print winatptr - print widget_win - - if winatptr[0] != widget_win: - self.hide(True) - - return True - - - if winatptr: win = winatptr[0] while win: - print "xx" - print self.window.window if win == self.window.window: break - win = win.get_toplevels() + win = capi.get_widget(gdk.gdk_window_get_parent (hash(win))) if not win: self.hide( True ) else: