From bc9539f187d81fe3e191dacf292b09885eec8ab8 Mon Sep 17 00:00:00 2001 From: Stephen Boddy Date: Thu, 28 Jun 2012 15:38:01 +0200 Subject: [PATCH 1/2] Adds ability to override the WMCLASS_NAME of a window. --- doc/terminator.1 | 3 +++ terminatorlib/optionparse.py | 2 ++ terminatorlib/window.py | 3 +++ 3 files changed, 8 insertions(+) diff --git a/doc/terminator.1 b/doc/terminator.1 index 4b746484..da6217ea 100644 --- a/doc/terminator.1 +++ b/doc/terminator.1 @@ -56,6 +56,9 @@ Set the terminal's working directory .B \-r, \-\-role=ROLE Set a custom WM_WINDOW_ROLE property on the window .TP +.B \-c, \-\-classname=CLASSNAME +Set a custom name (WM_CLASS) property on the window +.TP .B \-l, \-\-layout=LAYOUT Start Terminator with a specific layout. The argument here is the name of a saved layout. diff --git a/terminatorlib/optionparse.py b/terminatorlib/optionparse.py index 13a2a09d..0ab23ba2 100755 --- a/terminatorlib/optionparse.py +++ b/terminatorlib/optionparse.py @@ -66,6 +66,8 @@ command to execute inside the terminal, and its arguments')) dest='working_directory', help=_('Set the working directory')) parser.add_option('-r', '--role', dest='role', help=_('Set a custom \ WM_WINDOW_ROLE property on the window')) + parser.add_option('-c', '--classname', dest='classname', help=_('Set a \ +custom name (WM_CLASS) property on the window')) parser.add_option('-l', '--layout', dest='layout', help=_('Select a layout')) parser.add_option('-p', '--profile', dest='profile', help=_('Use a \ different profile as the default')) diff --git a/terminatorlib/window.py b/terminatorlib/window.py index 50fe79c9..cb4be4f4 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -75,6 +75,9 @@ class Window(Container, gtk.Window): if options.role is not None: self.set_role(options.role) + + if options.classname is not None: + self.set_wmclass(options.classname, self.wmclass_class) if options.geometry is not None: if not self.parse_geometry(options.geometry): From 54b4223c4d4de9cb3e56dca8604a7621bf44ca94 Mon Sep 17 00:00:00 2001 From: Stephen Boddy Date: Thu, 28 Jun 2012 18:07:00 +0200 Subject: [PATCH 2/2] Add some nice window icon setting abilities, plus I noticed a few options were missing from the manpage. --- doc/terminator.1 | 9 ++++++++ terminatorlib/optionparse.py | 2 ++ terminatorlib/window.py | 41 +++++++++++++++++++++++++++++------- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/doc/terminator.1 b/doc/terminator.1 index da6217ea..1a7294d2 100644 --- a/doc/terminator.1 +++ b/doc/terminator.1 @@ -63,6 +63,15 @@ Set a custom name (WM_CLASS) property on the window Start Terminator with a specific layout. The argument here is the name of a saved layout. .TP +.B \-p, \-\-profile=PROFILE +Use a different profile as the default +.TP +.B \-i, \-\-icon=FORCEDICON +Set a custom icon for the window (by file or name) +.TP +.B \-u, \-\-no-dbus +Disable DBus +.TP .B \-d, \-\-debug Enable debugging output (please use this when reporting bugs). This can be specified twice to enable a built-in python debugging server. diff --git a/terminatorlib/optionparse.py b/terminatorlib/optionparse.py index 0ab23ba2..7d4b3bff 100755 --- a/terminatorlib/optionparse.py +++ b/terminatorlib/optionparse.py @@ -71,6 +71,8 @@ custom name (WM_CLASS) property on the window')) parser.add_option('-l', '--layout', dest='layout', help=_('Select a layout')) parser.add_option('-p', '--profile', dest='profile', help=_('Use a \ different profile as the default')) + parser.add_option('-i', '--icon', dest='forcedicon', help=_('Set a custom \ +icon for the window (by file or name)')) parser.add_option('-u', '--no-dbus', action='store_true', dest='nodbus', help=_('Disable DBus')) parser.add_option('-d', '--debug', action='count', dest='debug', diff --git a/terminatorlib/window.py b/terminatorlib/window.py index cb4be4f4..0807e33d 100755 --- a/terminatorlib/window.py +++ b/terminatorlib/window.py @@ -60,7 +60,7 @@ class Window(Container, gtk.Window): self.register_signals(Window) self.set_property('allow-shrink', True) - self.apply_icon() + icon_to_apply='' self.register_callbacks() self.apply_config() @@ -78,12 +78,16 @@ class Window(Container, gtk.Window): if options.classname is not None: self.set_wmclass(options.classname, self.wmclass_class) + + if options.forcedicon is not None: + icon_to_apply = options.forcedicon if options.geometry is not None: if not self.parse_geometry(options.geometry): err('Window::__init__: Unable to parse geometry: %s' % options.geometry) + self.apply_icon(icon_to_apply) self.pending_set_rough_geometry_hint = False def do_get_property(self, prop): @@ -158,15 +162,36 @@ class Window(Container, gtk.Window): else: self.set_iconified(hidden) - def apply_icon(self): + def apply_icon(self, requested_icon): """Set the window icon""" icon_theme = gtk.IconTheme() - - try: - icon = icon_theme.load_icon(APP_NAME, 48, 0) - except (NameError, gobject.GError): - dbg('Unable to load 48px Terminator icon') - icon = self.render_icon(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_BUTTON) + icon = None + + if requested_icon: + try: + self.set_icon_from_file(requested_icon) + icon = self.get_icon() + except (NameError, gobject.GError): + dbg('Unable to load 48px %s icon as file' % (repr(requested_icon))) + + if requested_icon and icon is None: + try: + icon = icon_theme.load_icon(requested_icon, 48, 0) + except (NameError, gobject.GError): + dbg('Unable to load 48px %s icon' % (repr(requested_icon))) + + if icon is None: + try: + icon = icon_theme.load_icon(self.wmclass_name, 48, 0) + except (NameError, gobject.GError): + dbg('Unable to load 48px %s icon' % (self.wmclass_name)) + + if icon is None: + try: + icon = icon_theme.load_icon(APP_NAME, 48, 0) + except (NameError, gobject.GError): + dbg('Unable to load 48px Terminator icon') + icon = self.render_icon(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_BUTTON) self.set_icon(icon)