From: Adrian Iain Lam Date: Sun, 5 Feb 2023 05:34:26 +0000 (+0000) Subject: [v1.2] New re-design with icons only instead of labels. X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=indicator-keyboard-led.git [v1.2] New re-design with icons only instead of labels. This is due to many non-Unity desktop environments not showing indicator labels. --- diff --git a/README.md b/README.md index efa8f2f..cf90a7b 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,6 @@ Num lock and Scroll lock) without requiring any mouse or keyboard action. It also allows the lock keys to be toggled with mouse clicks, which could be useful for keyboards without Scroll lock keys or malfunctioning keyboards. -**Note**: This indicator is known to not work on Xfce / Xubuntu. -For more details, see [#6](https://github.com/adrianiainlam/indicator-keyboard-led/issues/6). - ## Screenshots ![indicator default][sc1] @@ -19,9 +16,6 @@ off. Menu of the indicator, shown on click. The locks can be toggled by clicking the respective item in the menu. -![indicator short][sc3] -Alternative (short) appearance of the indicator. - ## Installation from Ubuntu PPA sudo add-apt-repository ppa:adrianiainlam/indicator-keyboard-led @@ -31,14 +25,6 @@ Alternative (short) appearance of the indicator. After installation the postinst script will prompt you for preferences configuration. These config are explained here: -### Short label - -The default appearance of the indicator has long labels: -![⚫Num ⚫Caps ⚫Scroll][sc1] - -On small displays it may be preferable to use short labels: -![⚫N ⚫C ⚫S][sc3] - ### Order This option allows you to reorder the locks and also to hide @@ -48,24 +34,18 @@ Use a string consisting of zero or one occurrence of the characters 'N', 'C' and 'S' to set this option. For exampe, the default order is "Num Caps Scroll". -![⚫Num ⚫Caps ⚫Scroll][sc1] +![Num Caps Scroll][sc1] **CNS** changes this to "Caps Num Scroll". -![⚫Caps ⚫Num ⚫Scroll][sc4] +![Caps Num Scroll][sc4] **NC** hides Scroll lock from the default appearance. -![⚫Num ⚫Caps][sc5] - -**C**, combined with the previous *short* option, -would give a very compact Caps lock indicator. -![⚫C][sc6] +![Num Caps][sc5] [sc1]: screenshots/sc1.png [sc2]: screenshots/sc2.png -[sc3]: screenshots/sc3.png [sc4]: screenshots/sc4.png [sc5]: screenshots/sc5.png -[sc6]: screenshots/sc6.png ### xdotool @@ -109,7 +89,7 @@ It seems to be a common problem that Scroll Lock is not usable in Ubuntu. To solve this, do the following (assuming US keyboard): > # backup your symbols file - > sudo cp /usr/share/X11/xkb/symbols/us{,.distribution} + > sudo cp /usr/share/X11/xkb/symbols/us{,.distribution} > > Add the following line in the `xkb_symbols "basic" {` section. Do not worry > if that second line is not there, it is only there for some languages and @@ -117,7 +97,7 @@ To solve this, do the following (assuming US keyboard): > > ... > modifier_map Mod3 { Scroll_Lock }; <==<< Add this line - > + > > include "level3(ralt_switch)" <==<< before this line > }; > @@ -156,13 +136,26 @@ is correct and is an executable regular file. ## Localization -As motivated by Issue #1, this script has been localized to French (with -the assistance of Wikipedia and Google Translate). Corrections to the -translation, as well as translations to other languages, are welcome. -Feel free to create a pull request or open an issue. +Unfortunately, in order to work-around labels not being shown on newer +non-Unity-based Ubuntus, I have re-designed the indicators to be based +purely on icons instead. This means there will no longer be labels to +localize, and I instead have hardcoded icons. + +The icons are SVGs so you can still manually edit them if you want. +Look for the `` tag at the end of the SVGs. + +The menu items shown on click are still localized. + +I have included a screenshot below to show the old design (version 1.1) +which you can still install manually if you wish. -![indicator default, French locale][sc7] -Default appearance in a French locale. +> As motivated by Issue #1, this script has been localized to French (with +> the assistance of Wikipedia and Google Translate). Corrections to the +> translation, as well as translations to other languages, are welcome. +> Feel free to create a pull request or open an issue. +> +> ![indicator default, French locale][sc7] +> Default appearance in a French locale. [sc7]: screenshots/sc7.png @@ -171,7 +164,7 @@ Default appearance in a French locale. The program "indicator-keyboard-led.py" is released under the MIT License. Please refer to the file for the full text of the license. -The icon "indicator-keyboard-led.svg" is released to the public domain. +The icons "indicator-keyboard-led*.svg" are released to the public domain. ## Credits @@ -179,7 +172,7 @@ I would like to thank [Tobias Schlitt](https://github.com/tobyS), who wrote [indicator-chars](https://github.com/tobyS/indicator-chars) which I used as a reference when writing this software. -The icon used in the indicator (indicator-keyboard-led.svg) is modified +The icons used in the indicator (indicator-keyboard-led*.svg) are modified from the file "emblem-readonly.svg" by [Jakub Steiner](http://jimmac.musichall.cz) who released it to the public domain for the diff --git a/indicator-keyboard-led-C-off.svg b/indicator-keyboard-led-C-off.svg new file mode 100644 index 0000000..1b43e12 --- /dev/null +++ b/indicator-keyboard-led-C-off.svg @@ -0,0 +1,91 @@ + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + Adrian I Lam + http://jimmac.musichall.cz + + + caps lock + + + + + + + + + + + C + + diff --git a/indicator-keyboard-led-C-on.svg b/indicator-keyboard-led-C-on.svg new file mode 100644 index 0000000..3ce14c4 --- /dev/null +++ b/indicator-keyboard-led-C-on.svg @@ -0,0 +1,91 @@ + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + Adrian I Lam + http://jimmac.musichall.cz + + + caps lock + + + + + + + + + + + C + + diff --git a/indicator-keyboard-led-N-off.svg b/indicator-keyboard-led-N-off.svg new file mode 100644 index 0000000..9dc6a25 --- /dev/null +++ b/indicator-keyboard-led-N-off.svg @@ -0,0 +1,91 @@ + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + Adrian I Lam + http://jimmac.musichall.cz + + Caps Lock icon + caps lock + + + + + + + + + + + N + + diff --git a/indicator-keyboard-led-N-on.svg b/indicator-keyboard-led-N-on.svg new file mode 100644 index 0000000..d5dec65 --- /dev/null +++ b/indicator-keyboard-led-N-on.svg @@ -0,0 +1,91 @@ + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + Adrian I Lam + http://jimmac.musichall.cz + + Caps Lock icon + caps lock + + + + + + + + + + + N + + diff --git a/indicator-keyboard-led-S-off.svg b/indicator-keyboard-led-S-off.svg new file mode 100644 index 0000000..0261b04 --- /dev/null +++ b/indicator-keyboard-led-S-off.svg @@ -0,0 +1,91 @@ + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + Adrian I Lam + http://jimmac.musichall.cz + + + caps lock + + + + + + + + + + + S + + diff --git a/indicator-keyboard-led-S-on.svg b/indicator-keyboard-led-S-on.svg new file mode 100644 index 0000000..c06a5a2 --- /dev/null +++ b/indicator-keyboard-led-S-on.svg @@ -0,0 +1,91 @@ + + + + + + + + + + image/svg+xml + + + + Jakub Steiner + + + Adrian I Lam + http://jimmac.musichall.cz + + + caps lock + + + + + + + + + + + S + + diff --git a/indicator-keyboard-led.desktop b/indicator-keyboard-led.desktop index 78c9958..4eb3401 100755 --- a/indicator-keyboard-led.desktop +++ b/indicator-keyboard-led.desktop @@ -4,7 +4,7 @@ Name=indicator-keyboard-led Type=Application Exec=/usr/bin/indicator-keyboard-led.py -Icon=indicator-keyboard-led +Icon=indicator-keyboard-led-C-on Hidden=false NoDisplay=false X-GNOME-Autostart-enabled=true diff --git a/indicator-keyboard-led.py b/indicator-keyboard-led.py index 9213a83..73c897b 100755 --- a/indicator-keyboard-led.py +++ b/indicator-keyboard-led.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # # indicator-keyboard-led - simulate keyboard lock keys LED -# Copyright (c) 2017 Adrian I Lam +# Copyright (c) 2017-2023 Adrian I Lam s/spam/me/ # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), @@ -10,10 +10,10 @@ # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: -# +# # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. -# +# # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL @@ -38,26 +38,28 @@ gi.require_version('AppIndicator3', '0.1') from gi.repository import Gdk, Gtk, AppIndicator3 APP_NAME = 'indicator-keyboard-led' -APP_VERSION = '1.1' +APP_VERSION = '1.2' -ICON_LOCATION = '/usr/share/icons/hicolor/scalable/apps/' + APP_NAME + '.svg' +ICON_FOLDER = '/usr/share/icons/hicolor/scalable/apps/' import gettext t = gettext.translation(APP_NAME, '/usr/share/locale') _ = t.gettext class IndicatorKeyboardLED: - def __init__(self, short=False, order='NCS', xdotool=None): + def __init__(self, order='NCS', xdotool=None): self.validate_order(order) - self.indicator = AppIndicator3.Indicator.new( - APP_NAME, ICON_LOCATION, - AppIndicator3.IndicatorCategory.APPLICATION_STATUS) - self.indicator.set_status(AppIndicator3.IndicatorStatus.ACTIVE) + self.indicators = {} - if short: - self.locks = { 'N': _('N'), 'C': _('C'), 'S': _('S') } - else: - self.locks = { 'N': _('Num'), 'C': _('Caps'), 'S': _('Scroll') } + count = 0 + for i in order: + self.indicators[i] = AppIndicator3.Indicator.new( + '-'.join([APP_NAME, str(count), i]), + os.path.join(ICON_FOLDER, '-'.join([APP_NAME, i, 'off.svg'])), + AppIndicator3.IndicatorCategory.APPLICATION_STATUS) + self.indicators[i].set_status(AppIndicator3.IndicatorStatus.ACTIVE) + + count += 1 keymap = Gdk.Keymap.get_default() keymap.connect('state-changed', self.update_indicator, order) @@ -65,38 +67,37 @@ class IndicatorKeyboardLED: self.create_menu(xdotool, order) def create_menu(self, xdotool, order): - menu = Gtk.Menu() xdotool = xdotool or shutil.which('xdotool') - if xdotool and os.access(xdotool, os.X_OK) and os.path.isfile(xdotool): - def send_keypress(menuitem, keystroke): - subprocess.call([xdotool, 'key', keystroke]) - def new_menu_item(itemtype): - if itemtype == 'N': - item = Gtk.MenuItem.new_with_label(_('Num Lock')) - item.connect('activate', send_keypress, 'Num_Lock') - elif itemtype == 'C': - item = Gtk.MenuItem.new_with_label(_('Caps Lock')) - item.connect('activate', send_keypress, 'Caps_Lock') - elif itemtype == 'S': - item = Gtk.MenuItem.new_with_label(_('Scroll Lock')) - item.connect('activate', send_keypress, 'Scroll_Lock') - else: - raise ValueError('Invalid itemtype') - return item - - for i in order: + def send_keypress(menuitem, keystroke): + subprocess.call([xdotool, 'key', keystroke]) + def new_menu_item(itemtype): + if itemtype == 'N': + item = Gtk.MenuItem.new_with_label(_('Num Lock')) + item.connect('activate', send_keypress, 'Num_Lock') + elif itemtype == 'C': + item = Gtk.MenuItem.new_with_label(_('Caps Lock')) + item.connect('activate', send_keypress, 'Caps_Lock') + elif itemtype == 'S': + item = Gtk.MenuItem.new_with_label(_('Scroll Lock')) + item.connect('activate', send_keypress, 'Scroll_Lock') + else: + raise ValueError('Invalid itemtype') + return item + + for i in order: + menu = Gtk.Menu() + + if xdotool and os.access(xdotool, os.X_OK) and os.path.isfile(xdotool): menu.append(new_menu_item(i)) - menu.append(Gtk.SeparatorMenuItem()) - quit_item = Gtk.MenuItem.new_with_label(_('Quit')) - menu.append(quit_item) - quit_item.connect('activate', Gtk.main_quit) + quit_item = Gtk.MenuItem.new_with_label(_('Quit')) + menu.append(quit_item) + quit_item.connect('activate', Gtk.main_quit) - self.indicator.set_menu(menu) - menu.show_all() + self.indicators[i].set_menu(menu) + menu.show_all() def update_indicator(self, keymap, order): - labels = [] for i in order: if i == 'N': state = keymap.get_num_lock_state() @@ -106,8 +107,10 @@ class IndicatorKeyboardLED: state = keymap.get_scroll_lock_state() else: raise ValueError('Invalid value in ORDER') - labels += [('⚫' if state else '⚪') + self.locks[i]] - self.indicator.set_label(' '.join(labels), '') + + icon = os.path.join(ICON_FOLDER, '-'.join([APP_NAME, i, 'on.svg' if state else 'off.svg'])) + self.indicators[i].set_icon(icon) + def validate_order(self, order): order = order.upper() @@ -129,17 +132,15 @@ if __name__ == '__main__': parser = argparse.ArgumentParser( description='indicator-keyboard-led - simulate keyboard lock keys LED', formatter_class=argparse.ArgumentDefaultsHelpFormatter) - parser.add_argument('-s', '--short', required=False, action='store_true', - help='use short label, i.e. ⚫N ⚫C ⚫S instead of ⚫Num ⚫Caps ⚫Scroll') parser.add_argument('-o', '--order', required=False, default='NCS', help='specify the order of the locks displayed, e.g. CSN for ' - '⚫Caps ⚫Scroll ⚫Num, or NC for ⚫Num ⚫Caps without Scroll lock') + 'Caps Scroll Num, or NC for Num Caps without Scroll lock') parser.add_argument('-x', '--xdotool', required=False, help='provide full path to xdotool executable, ' 'e.g. "/usr/bin/xdotool"; ' 'if not specified, search in PATH') args = parser.parse_args() - IndicatorKeyboardLED(short=args.short, order=args.order, + IndicatorKeyboardLED(order=args.order, xdotool=args.xdotool) Gtk.main() diff --git a/indicator-keyboard-led.svg b/indicator-keyboard-led.svg deleted file mode 100644 index d711e58..0000000 --- a/indicator-keyboard-led.svg +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - image/svg+xml - - - - Jakub Steiner - - - Adrian I Lam - http://jimmac.musichall.cz - - Caps Lock icon - caps lock - - - - - - - - - - - - diff --git a/screenshots/sc1.png b/screenshots/sc1.png index 6acfa23..4b0e17e 100644 Binary files a/screenshots/sc1.png and b/screenshots/sc1.png differ diff --git a/screenshots/sc2.png b/screenshots/sc2.png index 228adee..ac4fab1 100644 Binary files a/screenshots/sc2.png and b/screenshots/sc2.png differ diff --git a/screenshots/sc3.png b/screenshots/sc3.png deleted file mode 100644 index aee6cb9..0000000 Binary files a/screenshots/sc3.png and /dev/null differ diff --git a/screenshots/sc4.png b/screenshots/sc4.png index 8852e62..42805b4 100644 Binary files a/screenshots/sc4.png and b/screenshots/sc4.png differ diff --git a/screenshots/sc5.png b/screenshots/sc5.png index ca10484..0d7ff8e 100644 Binary files a/screenshots/sc5.png and b/screenshots/sc5.png differ diff --git a/screenshots/sc6.png b/screenshots/sc6.png deleted file mode 100644 index b7db313..0000000 Binary files a/screenshots/sc6.png and /dev/null differ