Disable keybinding temporarily, not working yet

This commit is contained in:
Michael Webster 2013-03-09 15:37:17 -05:00
parent cab7f82899
commit c6f19e56bd
3 changed files with 23 additions and 25 deletions

View File

@ -35,15 +35,9 @@ import capi
gdk = CDLL("libgdk-x11-2.0.so.0") gdk = CDLL("libgdk-x11-2.0.so.0")
class GlobalKeyBinding(GObject.GObject, threading.Thread): class GlobalKeyBinding():
__gsignals__ = {
'activate':(GObject.SIGNAL_RUN_LAST, None,()),
}
def __init__(self): def __init__(self):
GObject.GObject.__init__(self)
threading.Thread.__init__(self)
self.setDaemon(True)
self.keymap = capi.get_widget (gdk.gdk_keymap_get_default()) self.keymap = capi.get_widget (gdk.gdk_keymap_get_default())
self.display = Display() self.display = Display()
@ -62,9 +56,7 @@ class GlobalKeyBinding(GObject.GObject, threading.Thread):
self.known_modifiers_mask |= modifier self.known_modifiers_mask |= modifier
def grab(self, key): def grab(self, key):
Gdk.threads_enter()
accelerator = key accelerator = key
Gdk.threads_leave()
keyval, modifiers = Gtk.accelerator_parse(accelerator) keyval, modifiers = Gtk.accelerator_parse(accelerator)
print keyval, modifiers print keyval, modifiers
# if not accelerator or (not keyval and not modifiers): # if not accelerator or (not keyval and not modifiers):
@ -73,16 +65,17 @@ class GlobalKeyBinding(GObject.GObject, threading.Thread):
# print "what" # print "what"
# return # return
count = c_int() count = c_int()
keys = KeymapKey * 10 array = (KeymapKey * 10)()
keys = cast(array, POINTER(KeymapKey))
self.keycode = gdk.gdk_keymap_get_entries_for_keyval(hash(self.keymap), keyval, byref(keys), byref(count)) self.keycode = gdk.gdk_keymap_get_entries_for_keyval(hash(self.keymap), keyval, byref(keys), byref(count))
#self.keycode= self.keymap.get_entries_for_keyval(keyval)[0].keycode #self.keycode= self.keymap.get_entries_for_keyval(keyval)[0].keycode
print keys print keys[0].keycode
self.modifiers = int(modifiers) self.modifiers = int(modifiers)
catch = error.CatchError(error.BadAccess) catch = error.CatchError(error.BadAccess)
for ignored_mask in self.ignored_masks: for ignored_mask in self.ignored_masks:
mod = modifiers | ignored_mask mod = modifiers | ignored_mask
result = self.root.grab_key(self.keycode, mod, True, X.GrabModeAsync, X.GrabModeSync, onerror=catch) result = self.root.grab_key(keys[0].keycode, mod, True, X.GrabModeAsync, X.GrabModeSync, onerror=catch)
self.display.sync() self.display.sync()
if catch.get_error(): if catch.get_error():
return False return False
@ -97,15 +90,17 @@ class GlobalKeyBinding(GObject.GObject, threading.Thread):
def idle(self): def idle(self):
print "caught" print "caught"
Gdk.threads_enter()
self.emit("activate") self.emit("activate")
Gdk.threads_leave()
return False return False
def activate(self):
GObject.idle_add(self.run)
def run(self): def run(self):
self.running = True self.running = True
wait_for_release = False wait_for_release = False
while self.running: while self.running:
print "running"
event = self.display.next_event() event = self.display.next_event()
self.current_event_time = event.time self.current_event_time = event.time
if event.detail == self.keycode and event.type == X.KeyPress and not wait_for_release: if event.detail == self.keycode and event.type == X.KeyPress and not wait_for_release:
@ -118,11 +113,12 @@ class GlobalKeyBinding(GObject.GObject, threading.Thread):
elif event.detail == self.keycode and wait_for_release: elif event.detail == self.keycode and wait_for_release:
if event.type == X.KeyRelease: if event.type == X.KeyRelease:
wait_for_release = False wait_for_release = False
GLib.idle_add(self.idle) GObject.idle_add(self.idle)
self.display.allow_events(X.AsyncKeyboard, event.time) self.display.allow_events(X.AsyncKeyboard, event.time)
else: else:
self.display.allow_events(X.ReplayKeyboard, event.time) self.display.allow_events(X.ReplayKeyboard, event.time)
def stop(self): def stop(self):
self.running = False self.running = False
self.ungrab() self.ungrab()
@ -132,6 +128,3 @@ class KeymapKey(Structure):
_fields_ = [("keycode", c_uint), _fields_ = [("keycode", c_uint),
("group", c_int), ("group", c_int),
("level", c_int)] ("level", c_int)]
class KeymapKeyMany(Structure):
_fields_ = [("keymap", KeymapKey*10)]

View File

@ -3,7 +3,7 @@
import gi import gi
gi.require_version("Gtk", "2.0") gi.require_version("Gtk", "2.0")
from gi.repository import Gtk, GdkPixbuf, Gdk from gi.repository import Gtk, GdkPixbuf, Gdk, GObject
from gi.repository import MatePanelApplet from gi.repository import MatePanelApplet
from gi.repository import Gio from gi.repository import Gio
@ -25,6 +25,12 @@ except Exception, e:
print e print e
sys.exit( 1 ) sys.exit( 1 )
from keybinding import GlobalKeyBinding
GObject.threads_init()
keybinder = GlobalKeyBinding()
gtk = CDLL("libgtk-x11-2.0.so.0") gtk = CDLL("libgtk-x11-2.0.so.0")
gdk = CDLL("libgdk-x11-2.0.so.0") gdk = CDLL("libgdk-x11-2.0.so.0")
@ -124,6 +130,7 @@ class MainWindow( object ):
self.settings.connect( "changed::border-width", self.toggleBorderWidth ) self.settings.connect( "changed::border-width", self.toggleBorderWidth )
self.settings.connect( "changed::opacity", self.toggleOpacity ) self.settings.connect( "changed::opacity", self.toggleOpacity )
def on_window1_destroy (self, widget, data=None): def on_window1_destroy (self, widget, data=None):
Gtk.main_quit() Gtk.main_quit()
sys.exit(0) sys.exit(0)
@ -370,7 +377,6 @@ class MainWindow( object ):
self.paneholder.pack_start( ImageBox, False, False, 0 ) self.paneholder.pack_start( ImageBox, False, False, 0 )
self.paneholder.pack_start( PluginPane, False, False, 0 ) self.paneholder.pack_start( PluginPane, False, False, 0 )
self.tooltips.disable() self.tooltips.disable()
#print u"Loading", (time.time() - start), "s" #print u"Loading", (time.time() - start), "s"
def SetPaneColors( self, items ): def SetPaneColors( self, items ):
@ -544,6 +550,7 @@ class MenuWin( object ):
self.bind_hot_key() self.bind_hot_key()
def onBindingPress(self): def onBindingPress(self):
print "press"
try: try:
if self.mainwin.window.flags() & Gtk.VISIBLE: if self.mainwin.window.flags() & Gtk.VISIBLE:
self.mainwin.window.hide() self.mainwin.window.hide()
@ -687,10 +694,10 @@ class MenuWin( object ):
self.sizeButton() self.sizeButton()
def bind_hot_key (self): def bind_hot_key (self):
return
try: try:
self.binder = keybinding.GlobalKeyBinding() keybinder.grab( self.hotkeyText )
self.binder.grab( self.hotkeyText ) keybinder.connect("activate", self.onBindingPress)
self.binder.connect("activate", self.onBindingPress)
# Binding menu to hotkey # Binding menu to hotkey
print "Binding to Hot Key: " + self.hotkeyText print "Binding to Hot Key: " + self.hotkeyText

View File

@ -33,8 +33,6 @@ import matemenu
from user import home from user import home
GObject.threads_init()
# i18n # i18n
gettext.install("mintmenu", "/usr/share/linuxmint/locale") gettext.install("mintmenu", "/usr/share/linuxmint/locale")