Skip to content

Commit

Permalink
add gtk3 mouse support: motion, clicks and scrolling
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@6206 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Apr 27, 2014
1 parent a6ae531 commit c2d9eb1
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 15 deletions.
7 changes: 5 additions & 2 deletions src/xpra/client/client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,5 +333,8 @@ def do_button_release_event(self, event):
def do_scroll_event(self, event):
if self._client.readonly:
return
self._button_action(self.SCROLL_MAP[event.direction], event, True)
self._button_action(self.SCROLL_MAP[event.direction], event, False)
button_mapping = self.SCROLL_MAP.get(event.direction, -1)
mouselog("do_scroll_event direction=%s, button_mapping=%s", event.direction, button_mapping)
if button_mapping>=0:
self._button_action(button_mapping, event, True)
self._button_action(button_mapping, event, False)
6 changes: 6 additions & 0 deletions src/xpra/client/gtk2/gtk2_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"COMBO" : gdk.WINDOW_TYPE_HINT_COMBO,
"DND" : gdk.WINDOW_TYPE_HINT_DND
}
GTK2_BUTTON_MASK = {gtk.gdk.BUTTON1_MASK : 1,
gtk.gdk.BUTTON2_MASK : 2,
gtk.gdk.BUTTON3_MASK : 3,
gtk.gdk.BUTTON4_MASK : 4,
gtk.gdk.BUTTON5_MASK : 5}
# Map scroll directions back to mouse buttons. Mapping is taken from
# gdk/x11/gdkevents-x11.c.
GTK2_SCROLL_MAP = {
Expand All @@ -70,6 +75,7 @@ class GTK2WindowBase(GTKClientWindowBase):
OR_TYPE_HINTS = GTK2_OR_TYPE_HINTS
NAME_TO_HINT = GTK2_NAME_TO_HINT
SCROLL_MAP = GTK2_SCROLL_MAP
BUTTON_MASK = GTK2_BUTTON_MASK

WINDOW_STATE_FULLSCREEN = gdk.WINDOW_STATE_FULLSCREEN
WINDOW_STATE_MAXIMIZED = gdk.WINDOW_STATE_MAXIMIZED
Expand Down
78 changes: 70 additions & 8 deletions src/xpra/client/gtk3/client_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,69 @@
from xpra.codecs.argb.argb import unpremultiply_argb, byte_buffer_to_buffer #@UnresolvedImport


GTK3_WINDOW_EVENT_MASK = Gdk.EventMask.STRUCTURE_MASK | Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK \
| Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK \
| Gdk.EventMask.PROPERTY_CHANGE_MASK | Gdk.EventMask.SCROLL_MASK

GTK3_BUTTON_MASK = {Gdk.ModifierType.BUTTON1_MASK : 1,
Gdk.ModifierType.BUTTON2_MASK : 2,
Gdk.ModifierType.BUTTON3_MASK : 3,
Gdk.ModifierType.BUTTON4_MASK : 4,
Gdk.ModifierType.BUTTON5_MASK : 5}

GTK3_SCROLL_MAP = {
Gdk.ScrollDirection.UP : 4,
Gdk.ScrollDirection.DOWN : 5,
Gdk.ScrollDirection.LEFT : 6,
Gdk.ScrollDirection.RIGHT: 7,
#Gdk.ScrollDirection.SMOOTH would require special handling
# calling gdk_event_get_scroll_deltas()
}

GTK3_OR_TYPE_HINTS = [Gdk.WindowTypeHint.DIALOG,
Gdk.WindowTypeHint.MENU,
Gdk.WindowTypeHint.TOOLBAR,
#Gdk.WindowTypeHint.SPLASHSCREEN,
#Gdk.WindowTypeHint.UTILITY,
#Gdk.WindowTypeHint.DOCK,
#Gdk.WindowTypeHint.DESKTOP,
Gdk.WindowTypeHint.DROPDOWN_MENU,
Gdk.WindowTypeHint.POPUP_MENU,
Gdk.WindowTypeHint.TOOLTIP,
#Gdk.WindowTypeHint.NOTIFICATION,
Gdk.WindowTypeHint.COMBO,
Gdk.WindowTypeHint.DND]

GTK3_NAME_TO_HINT = {
"NORMAL" : Gdk.WindowTypeHint.NORMAL,
"DIALOG" : Gdk.WindowTypeHint.DIALOG,
"MENU" : Gdk.WindowTypeHint.MENU,
"TOOLBAR" : Gdk.WindowTypeHint.TOOLBAR,
"SPLASH" : Gdk.WindowTypeHint.SPLASHSCREEN,
"UTILITY" : Gdk.WindowTypeHint.UTILITY,
"DOCK" : Gdk.WindowTypeHint.DOCK,
"DESKTOP" : Gdk.WindowTypeHint.DESKTOP,
"DROPDOWN_MENU" : Gdk.WindowTypeHint.DROPDOWN_MENU,
"POPUP_MENU" : Gdk.WindowTypeHint.POPUP_MENU,
"TOOLTIP" : Gdk.WindowTypeHint.TOOLTIP,
"NOTIFICATION" : Gdk.WindowTypeHint.NOTIFICATION,
"COMBO" : Gdk.WindowTypeHint.COMBO,
"DND" : Gdk.WindowTypeHint.DND
}


"""
GTK3 version of the ClientWindow class
"""
class ClientWindow(GTKClientWindowBase):

WINDOW_POPUP = Gtk.WindowType.POPUP
WINDOW_TOPLEVEL = Gtk.WindowType.TOPLEVEL
#where have those values gone?
#gi/pygtk3 docs are terrible for this
WINDOW_EVENT_MASK = 0
OR_TYPE_HINTS = []
NAME_TO_HINT = { }
SCROLL_MAP = {}
WINDOW_POPUP = Gtk.WindowType.POPUP
WINDOW_TOPLEVEL = Gtk.WindowType.TOPLEVEL
WINDOW_EVENT_MASK = GTK3_WINDOW_EVENT_MASK
BUTTON_MASK = GTK3_BUTTON_MASK
SCROLL_MAP = GTK3_SCROLL_MAP
OR_TYPE_HINTS = GTK3_OR_TYPE_HINTS
NAME_TO_HINT = GTK3_NAME_TO_HINT

WINDOW_STATE_FULLSCREEN = Gdk.WindowState.FULLSCREEN
WINDOW_STATE_MAXIMIZED = Gdk.WindowState.MAXIMIZED
Expand All @@ -49,6 +99,18 @@ def init_window(self, metadata):
# see: https://bugs.kde.org/show_bug.cgi?id=274485
# does not work with gtk3? what the??
#self.set_data(strtobytes("_kde_no_window_grab"), 1)
def motion(w, event):
self.do_motion_notify_event(event)
self.connect("motion-notify-event", motion)
def press(w, event):
self.do_button_press_event(event)
self.connect("button-press-event", press)
def release(w, event):
self.do_button_release_event(event)
self.connect("button-release-event", release)
def scroll(w, event):
self.do_scroll_event(event)
self.connect("scroll-event", scroll)

def new_backing(self, w, h):
self._backing = self.make_new_backing(CairoBacking, w, h)
Expand Down
6 changes: 1 addition & 5 deletions src/xpra/client/gtk_base/gtk_client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,11 +410,7 @@ def _pointer_modifiers(self, event):
pointer = (int(event.x_root), int(event.y_root))
modifiers = self._client.mask_to_names(event.state)
buttons = []
for mask, button in {gtk.gdk.BUTTON1_MASK : 1,
gtk.gdk.BUTTON2_MASK : 2,
gtk.gdk.BUTTON3_MASK : 3,
gtk.gdk.BUTTON4_MASK : 4,
gtk.gdk.BUTTON5_MASK : 5}.items():
for mask, button in self.BUTTON_MASK.items():
if event.state & mask:
buttons.append(button)
return pointer, modifiers, buttons
Expand Down

0 comments on commit c2d9eb1

Please sign in to comment.