[X2go-Commits] python-x2go.git - master (branch) updated: 0.1.1.4-83-g8c2c5b4

X2go dev team git-admin at x2go.org
Thu Dec 8 19:29:13 CET 2011


The branch, master has been updated
       via  8c2c5b48cf06571c629b55782175e74cc99b7b5b (commit)
       via  02d00cf85ff6e2fc9bcde04c2c9118e423c519c8 (commit)
       via  998741e75447c444478a8165d158f28892cbb719 (commit)
       via  af2a1f81c8b96df6ac049616847e22d99102791b (commit)
      from  584c53129bd67f9a4dd7c19f0bbc69f713073eb6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 8c2c5b48cf06571c629b55782175e74cc99b7b5b
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Thu Dec 8 19:29:03 2011 +0100

    Add support for bringing session windows on top.

commit 02d00cf85ff6e2fc9bcde04c2c9118e423c519c8
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Thu Dec 8 14:49:49 2011 +0100

    Add support for session window title renaming.

commit 998741e75447c444478a8165d158f28892cbb719
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Thu Dec 8 13:48:51 2011 +0100

    use control session method to access port of remote server

commit af2a1f81c8b96df6ac049616847e22d99102791b
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Thu Dec 8 13:43:32 2011 +0100

    use control session method to access hostname of remote server

-----------------------------------------------------------------------

Summary of changes:
 debian/changelog                  |    2 +
 x2go/backends/control/_stdout.py  |    6 +++
 x2go/backends/terminal/_stdout.py |   67 +++++++++++++++++++++++++++++++++---
 x2go/client.py                    |   26 ++++++++++++++
 x2go/session.py                   |   39 ++++++++++++++++++++--
 x2go/utils.py                     |   58 ++++++++++++++++++++++++++++++++
 6 files changed, 189 insertions(+), 9 deletions(-)

The diff of changes is:
diff --git a/debian/changelog b/debian/changelog
index eb74667..81a5ccc 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -18,6 +18,8 @@ python-x2go (0.1.1.9-0-x2go1) UNRELEASED; urgency=low
     - Fix for list processing in  INI files.
     - Make terminal backend ,,applications'' aware.
     - Allow session parameter change for already registered sessions.
+    - Add support for session window title renaming.
+    - Add support for bringing session windows on top.
 
  -- Mike Gabriel <mike.gabriel at das-netzwerkteam.de>  Wed, 12 Oct 2011 10:54:23 +0200
 
diff --git a/x2go/backends/control/_stdout.py b/x2go/backends/control/_stdout.py
index 9f2f9a3..0fb0171 100644
--- a/x2go/backends/control/_stdout.py
+++ b/x2go/backends/control/_stdout.py
@@ -146,6 +146,12 @@ class X2goControlSessionSTDOUT(paramiko.SSHClient):
 
         self.session_died = False
 
+    def get_hostname(self):
+        return self.hostname
+
+    def get_port(self):
+        return self.port
+
     def load_session_host_keys(self):
         if self.known_hosts is not None:
             utils.touch_file(self.known_hosts)
diff --git a/x2go/backends/terminal/_stdout.py b/x2go/backends/terminal/_stdout.py
index 3817b43..07b0be9 100644
--- a/x2go/backends/terminal/_stdout.py
+++ b/x2go/backends/terminal/_stdout.py
@@ -751,6 +751,60 @@ class X2goTerminalSessionSTDOUT(object):
         """
         return self.params.depth
 
+    def _auto_session_window_title(self):
+
+        _generic_title = 'X2GO-%s' % self.session_info.name
+
+        if self.params.session_type == 'D':
+            if self.set_session_title:
+
+                if not self.session_title:
+                    self.session_title = '%s for %s@%s' % (self.params.cmd, self.control_session.remote_username(), self.control_session.get_hostname())
+
+            else:
+                # session title fallback... (like X2Go server does it...)
+                self.session_title = _generic_title
+
+        else:
+            # do nothing for rootless sessions
+            self.session_title = _generic_title
+
+        if self.session_title != _generic_title:
+            self.set_session_window_title(title=self.session_title)
+
+
+    def set_session_window_title(self, title=''):
+        """\
+        Modify session window title. If the session ID does not occur in the
+        given title, it will be prepended, so that every X2Go session window
+        always contains the X2Go session ID of that window.
+
+        @param title: new title for session window
+        @type title: C{str}
+
+        """
+        self.session_title = title
+
+        if self.session_info.name not in title:
+            title = '%s (X2GO-%s)' % (title, self.session_info.name)
+
+        gevent.spawn(utils.set_session_window_title,
+                     session_name=self.session_info.name,
+                     title=title,
+                     timeout=30,
+                    )
+
+    def raise_session_window(self):
+        """\
+        Try to lift the session window above all other windows and bring
+        it to focus.
+
+        """
+        gevent.spawn(utils.raise_session_window,
+                     session_name=self.session_info.name,
+                     timeout=30,
+                    )
+
     def has_command(self, cmd):
         """\
         Verify if the command <cmd> exists on the X2go server.
@@ -923,12 +977,6 @@ class X2goTerminalSessionSTDOUT(object):
         if self.params.cmd == 'XDMCP' and self.params.xdmcp_server:
             cmd_line = ['X2GOXDMCP=%s' % self.params.xdmcp_server] + cmd_line
 
-        if self.set_session_title:
-            cmd_line = ['X2GO_CLIENTFEATURE_SET_SESSIONTITLE=enabled '] + cmd_line
-
-        if self.session_title:
-            cmd_line = ['X2GO_SESSION_WINDOW_TITLE="%s" ' % self.session_title] + cmd_line
-
         (stdin, stdout, stderr) = self.control_session._x2go_exec_command(cmd_line)
 
         _stdout = stdout.read()
@@ -970,6 +1018,9 @@ class X2goTerminalSessionSTDOUT(object):
         self.proxy_subprocess = self.proxy.start_proxy()
         self.active_threads.append(self.proxy)
 
+        self._auto_session_window_title()
+        self.raise_session_window()
+
         return self.ok()
 
     def resume(self):
@@ -1015,6 +1066,10 @@ class X2goTerminalSessionSTDOUT(object):
         self.params.depth = self.session_info.name.split('_')[2][2:]
         # on a session resume the user name comes in as a user ID. We have to translate this...
         self.session_info.username = self.control_session.remote_username()
+
+        self._auto_session_window_title()
+        self.raise_session_window()
+
         return self.ok()
 
     def suspend(self):
diff --git a/x2go/client.py b/x2go/client.py
index 7928adf..e8db628 100644
--- a/x2go/client.py
+++ b/x2go/client.py
@@ -1182,6 +1182,32 @@ class X2goClient(object):
         self.session_registry(session_uuid).set_print_action(print_action=print_action, **kwargs)
     __set_session_print_action = set_session_print_action
 
+    def set_session_window_title(self, session_uuid, title=''):
+        """\
+        Modify session window title. If the session ID does not occur in the
+        given title, it will be prepended, so that every X2Go session window
+        always contains the X2Go session ID of that window.
+
+        @param session_uuid: the X2go session's UUID registry hash
+        @type session_uuid: C{str}
+        @param title: new title for session window
+        @type title: C{str}
+
+        """
+        self.session_registry(session_uuid).set_session_window_title(title=title)
+    __set_session_window_title = set_session_window_title
+
+    def raise_session_window(self, session_uuid):
+        """\
+        Try to lift the session window above all other windows and bring
+        it to focus.
+
+        @param session_uuid: the X2go session's UUID registry hash
+        @type session_uuid: C{str}
+        """
+        self.session_registry(session_uuid).raise_session_window()
+    __raise_session_window = raise_session_window
+
     def start_session(self, session_uuid):
         """\
         Start a new X2go session on the remote X2go server. This method
diff --git a/x2go/session.py b/x2go/session.py
index fbd4cbd..26f812f 100644
--- a/x2go/session.py
+++ b/x2go/session.py
@@ -522,7 +522,6 @@ class X2goSession(object):
             return self.control_params['username']
     __get_username = get_username
 
-
     def user_is_x2gouser(self, username=None):
         """\
         Check if a given user is valid server-side X2go user.
@@ -575,7 +574,7 @@ class X2goSession(object):
         @rtype: C{str}
 
         """
-        self.server = self.control_session.hostname
+        self.server = self.control_session.get_hostname()
         return self.server
     __get_server_hostname = get_server_hostname
 
@@ -589,7 +588,7 @@ class X2goSession(object):
         @rtype: C{str}
 
         """
-        return self.control_session.port
+        return self.control_session.get_port()
     __get_server_port = get_server_port
 
     def get_session_name(self):
@@ -617,6 +616,18 @@ class X2goSession(object):
         return None
     __get_session_cmd = get_session_cmd
 
+    def get_session_title(self):
+        """\
+        Retrieve the session window title of this
+        session.
+
+        @return: session window title
+        @rtype: C{str}
+
+        """
+        if self.terminal_session is not None:
+            return self.terminal_session.session_title
+
     def get_control_session(self):
         """\
         Retrieve the control session (C{X2goControlSession*} backend) of this L{X2goSession}.
@@ -850,6 +861,28 @@ class X2goSession(object):
         return retval
     __disconnect = disconnect
 
+    def set_session_window_title(self, title=''):
+        """\
+        Modify session window title. If the session ID does not occur in the
+        given title, it will be prepended, so that every X2Go session window
+        always contains the X2Go session ID of that window.
+
+        @param title: new title for session window
+        @type title: C{str}
+
+        """
+        if self.terminal_session is not None:
+            self.terminal_session.set_session_window_title(title=title)
+
+    def raise_session_window(self):
+        """\
+        Try to lift the session window above all other windows and bring
+        it to focus.
+
+        """
+        if self.terminal_session is not None:
+            self.terminal_session.raise_session_window()
+
     def set_print_action(self, print_action, **kwargs):
         """\
         If X2go client-side printing is enable within this X2go session you can use
diff --git a/x2go/utils.py b/x2go/utils.py
index ab23c19..8ec0862 100644
--- a/x2go/utils.py
+++ b/x2go/utils.py
@@ -35,6 +35,8 @@ import gevent
 import string
 import re
 import subprocess
+import Xlib
+import Xlib.display
 
 # Python X2go modules
 from defaults import X2GOCLIENT_OS as _X2GOCLIENT_OS
@@ -462,3 +464,59 @@ def is_color_depth_ok(depth_session, depth_local):
         return True;
     return False
 
+def set_session_window_title(session_name, title, timeout=0):
+
+    timeout += 1
+    while timeout:
+
+        timeout -= 1
+        success = False
+
+        if _X2GOCLIENT_OS != 'Windows':
+
+            display = Xlib.display.Display()
+            root = display.screen().root
+
+            windowIDs = root.get_full_property(display.intern_atom('_NET_CLIENT_LIST'), Xlib.X.AnyPropertyType).value
+            for windowID in windowIDs:
+                window = display.create_resource_object('window', windowID)
+                if session_name in window.get_wm_name():
+                    success = True
+                    window.set_wm_name('%s' % str(title))
+                    window.set_wm_icon_name('%s' % str(title))
+                    display.sync()
+                    break
+
+        if success:
+            break
+
+        gevent.sleep(1)
+
+def raise_session_window(session_name, timeout=0):
+
+    timeout += 1
+    while timeout:
+
+        timeout -= 1
+        success = False
+
+        if _X2GOCLIENT_OS != 'Windows':
+
+            display = Xlib.display.Display()
+            root = display.screen().root
+
+            windowIDs = root.get_full_property(display.intern_atom('_NET_CLIENT_LIST'), Xlib.X.AnyPropertyType).value
+            for windowID in windowIDs:
+                window = display.create_resource_object('window', windowID)
+                if session_name in window.get_wm_name():
+                    success = True
+                    window.set_input_focus(Xlib.X.RevertToParent, Xlib.X.CurrentTime)
+                    window.configure(stack_mode=Xlib.X.Above)
+                    window.circulate(Xlib.X.RaiseLowest)
+                    display.sync()
+                    break
+
+        if success:
+            break
+
+        gevent.sleep(1)


hooks/post-receive
-- 
python-x2go.git (Python X2Go Client API)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "python-x2go.git" (Python X2Go Client API).




More information about the x2go-commits mailing list