Skip to content

Commit

Permalink
#469 add focus debugging loggers to both client and server
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@5444 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Feb 13, 2014
1 parent 7d8128b commit 4792b1b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/xpra/client/client_window_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from xpra.log import Logger
log = Logger("window")
plog = Logger("paint")
focuslog = Logger("focus")

#pretend to draw the windows, but don't actually do anything
USE_FAKE_BACKING = os.environ.get("XPRA_USE_FAKE_BACKING", "0")=="1"
Expand Down Expand Up @@ -290,7 +291,7 @@ def can_have_spinner(self):


def _unfocus(self):
self.debug("_unfocus() wid=%s", self._id)
focuslog("_unfocus() wid=%s", self._id)
if self._client._focused==self._id:
self._client.update_focus(self._id, False)

Expand Down
4 changes: 3 additions & 1 deletion src/xpra/server/server_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from xpra.log import Logger
log = Logger("server")
keylog = Logger("keyboard")
focuslog = Logger("focus")

from xpra.keyboard.mask import DEFAULT_MODIFIER_MEANINGS
from xpra.server.server_core import ServerCore
Expand Down Expand Up @@ -987,7 +988,7 @@ def _clear_keys_pressed(self):


def _focus(self, server_source, wid, modifiers):
log("_focus(%s,%s)", wid, modifiers)
focuslog("_focus(%s,%s)", wid, modifiers)

def get_focus(self):
#can be overriden by subclasses that do manage focus
Expand Down Expand Up @@ -1235,6 +1236,7 @@ def _set_client_properties(self, proto, wid, window, new_client_properties):

def _process_focus(self, proto, packet):
wid = packet[1]
focuslog("process_focus: wid=%s", wid)
if len(packet)>=3:
modifiers = packet[2]
else:
Expand Down
7 changes: 4 additions & 3 deletions src/xpra/x11/gtk_x11/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

from xpra.log import Logger
log = Logger("x11", "window")
focuslog = Logger("x11", "window", "focus")

if gtk.pygtk_version<(2,17):
log.error("your version of PyGTK is too old - expect some bugs")
Expand Down Expand Up @@ -1348,7 +1349,7 @@ def give_client_focus(self):
trap.swallow_synced(self.do_give_client_focus)

def do_give_client_focus(self):
log("Giving focus to client")
focuslog("Giving focus to %s", self.client_window)
# Have to fetch the time, not just use CurrentTime, both because ICCCM
# says that WM_TAKE_FOCUS must use a real time and because there are
# genuine race conditions here (e.g. suppose the client does not
Expand All @@ -1369,10 +1370,10 @@ def do_give_client_focus(self):
# (unless they have a modal window), and just expect to get focus from
# the WM's XSetInputFocus.
if bool(self._input_field):
log("... using XSetInputFocus")
focuslog("... using XSetInputFocus")
X11Window.XSetInputFocus(get_xwindow(self.client_window), now)
if "WM_TAKE_FOCUS" in self.get_property("protocols"):
log("... using WM_TAKE_FOCUS")
focuslog("... using WM_TAKE_FOCUS")
send_wm_take_focus(self.client_window, now)

################################
Expand Down
9 changes: 6 additions & 3 deletions src/xpra/x11/gtk_x11/world_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from xpra.x11.gtk_x11.prop import prop_set
from xpra.log import Logger
log = Logger("x11", "window")
focuslog = Logger("x11", "window", "focus")

# This file defines Xpra's top-level widget. It is a magic window that
# always and exactly covers the entire screen (possibly crossing multiple
Expand Down Expand Up @@ -137,19 +138,20 @@ def do_map(self, *args):
send_wm_take_focus(self.window, current_time)

def do_focus_in_event(self, *args):
log("world window got focus")
focuslog("world window got focus")
if not self.get_property("has-toplevel-focus"):
#super(WorldWindow, self).do_focus_in_event(*args)
gtk.Window.do_focus_in_event(self, *args)
self.reset_x_focus()

def do_focus_out_event(self, *args):
focuslog("world window lost focus")
# Do nothing -- harder:
self.stop_emission("focus-out-event")
return False

def _take_focus(self):
log("Focus -> world window")
focuslog("Take Focus -> world window")
assert self.flags() & gtk.REALIZED
# Weird hack: we are a GDK window, and the only way to properly get
# input focus to a GDK window is to send it WM_TAKE_FOCUS. So this is
Expand All @@ -160,13 +162,14 @@ def _take_focus(self):
send_wm_take_focus(self.window, now)

def reset_x_focus(self):
log("widget with focus: %s", self.get_focus())
focuslog("reset_x_focus: widget with focus: %s", self.get_focus())
def do_reset_x_focus():
self._take_focus()
root_set("_NET_ACTIVE_WINDOW", "u32", constants["XNone"])
trap.swallow_synced(do_reset_x_focus)

def _after_set_focus(self, *args):
focuslog("after_set_focus")
# GTK focus has changed. See comment in __init__ for why this isn't a
# default handler.
if self.get_focus() is not None:
Expand Down
10 changes: 6 additions & 4 deletions src/xpra/x11/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

from xpra.log import Logger
log = Logger("server")
focuslog = Logger("server", "focus")

import xpra
from xpra.os_util import StringIOClass
Expand Down Expand Up @@ -458,13 +459,13 @@ def _bell_signaled(self, wm, event):


def _focus(self, server_source, wid, modifiers):
log("_focus(%s, %s, %s) has_focus=%s", server_source, wid, modifiers, self._has_focus)
focuslog("focus wid=%s has_focus=%s", wid, self._has_focus)
if self._has_focus==wid:
#nothing to do!
return
had_focus = self._id_to_window.get(self._has_focus)
def reset_focus():
log("reset_focus() %s / %s had focus", self._has_focus, had_focus)
focuslog("reset_focus() %s / %s had focus", self._has_focus, had_focus)
self._clear_keys_pressed()
# FIXME: kind of a hack:
self._has_focus = 0
Expand All @@ -478,12 +479,13 @@ def reset_focus():
#not found! (go back to root)
return reset_focus()
if window.is_OR():
log.warn("focus(..) cannot focus OR window: %s", window)
focuslog.warn("focus(..) cannot focus OR window: %s", window)
return
log("focus(%s, %s, %s) giving focus to %s", server_source, wid, modifiers, window)
focuslog("focus: giving focus to %s", window)
#using idle_add seems to prevent some focus races:
gobject.idle_add(window.give_client_focus)
if server_source and modifiers is not None:
focuslog("focus: will set modified mask to %s", modifiers)
server_source.make_keymask_match(modifiers)
self._has_focus = wid

Expand Down

0 comments on commit 4792b1b

Please sign in to comment.