aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-06-01 00:28:11 +0200
committerMattias Andrée <maandree@operamail.com>2014-06-01 00:28:11 +0200
commit8c9f82f486a07d86645726ad8044121198e684ba (patch)
tree4251ddcd5c4d4cb15aab79776d9c2794b913ee86 /src
parentupdate dist (diff)
downloadxpybar-8c9f82f486a07d86645726ad8044121198e684ba.tar.gz
xpybar-8c9f82f486a07d86645726ad8044121198e684ba.tar.bz2
xpybar-8c9f82f486a07d86645726ad8044121198e684ba.tar.xz
setproctitle1.2
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/__main__.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/__main__.py b/src/__main__.py
index 126ca49..c545a66 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -440,6 +440,37 @@ class Bar:
return n
+## Set process title
+def setproctitle(title):
+ '''
+ Set process title
+
+ @param title:str The title of the process
+ '''
+ import ctypes
+ try:
+ # Remove path, keep only the file,
+ # otherwise we get really bad effects, namely
+ # the name title is truncates by the number
+ # of slashes in the title. At least that is
+ # the observed behaviour when using procps-ng.
+ title = title.split('/')[-1]
+ # Create strng buffer with title
+ title = title.encode(sys.getdefaultencoding(), 'replace')
+ title = ctypes.create_string_buffer(title)
+ if 'linux' in sys.platform:
+ # Set process title on Linux
+ libc = ctypes.cdll.LoadLibrary('libc.so.6')
+ libc.prctl(15, ctypes.byref(title), 0, 0, 0)
+ elif 'bsd' in sys.platform:
+ # Set process title on at least FreeBSD
+ libc = ctypes.cdll.LoadLibrary('libc.so.7')
+ libc.setproctitle(ctypes.create_string_buffer(b'-%s'), title)
+ except:
+ pass
+setproctitle(sys.argv[0])
+
+
## Read command line arguments
parser = ArgParser('A highly extensible minimalistic dock panel',
sys.argv[0] + ' [options] [-- configuration-options]',