LockState v1.1

Core libraries and systems
Post Reply
Message
Author
User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

LockState v1.1

#1 Post by SFR »

This utility monitors the state of CapsLock, NumLock and ScrollLock* keys and shows status icons in system tray.
Right-clicking any icon displays a popup menu, where you can show/hide selected indicator or quit the app.
Just note that if you have only one icon enabled, it cannot be hidden.

The attached archive contains source code, two PETs (for 32bit and 64bit systems) and TXZ package for Fatdog - all built in FD, too.
Briefly tested in Slacko-5.7 and Tahr64-6.0.5, but may not work on other/older ones.

Written in C/GTK+-2.0 on Fatdog64-710.
Since I'm completely hopeless at drawing, I had to borrow status icons from somewhere - in this case LXPanel project.
EDIT: as of version 0.2, LockState uses status icons created by vovchik.
___________

* ScrollLock: in Puppyland this key is usually inactive. So, if xmodmap -pm shows:

Code: Select all

[...]
mod1        Alt_L (0x40),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3        
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)
[...]
and you want to be able to monitor ScrollLock's state, just do this:

Code: Select all

xmodmap -e 'add mod3 = Scroll_Lock'
and you should get that:

Code: Select all

[...]
mod1        Alt_L (0x40),  Meta_L (0xcd)
mod2        Num_Lock (0x4d)
mod3        Scroll_Lock (0x4e)
mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)
[...]
___________

Changelog:

Version 1.1:
- removed the micro-delay between displaying icons - it's no longer necessary with newer LxQt-Panel in Fatdog
- fixed quitting the app when Preferences window is open
- changed program icon

Version 1.0:
- left-clicking an icon toggles the state of the corresponding key
- the last (hopefully) memory leak has been fixed
- minor rearrangements in the code

Version 0.5:
- added option to draw icons in reversed order (Scroll->Num->Caps), because some panels (JWM's, FBPanel...) draw tray icons from right to left
- added 'Redraw icons' option
- fixed some minor memory leaks
- fixed segfault with glib < 2.36
- small bugfix in sanity checks
- code improvements

Version 0.4:
- added Preferences dialog for colors & symbols customization
- some internal rearrangements/improvements

Version 0.3:
- improvement: no need for temp files anymore, all done internally via rsvg & pixbufs

Version 0.2:
- new status icons (thanks to vovchik)
- icons are embedded in the code (thanks to vovchik)

Version 0.1:
- initial release

Enjoy &
Greetings!
Attachments
LockState-1.1.tar.gz
MD5: f1331bb662ab2a06f715207d4fdae540 LockState-1.1.tar.gz
(69.91 KiB) Downloaded 348 times
LockState-1.0.tar.gz
MD5: 598a0a9d955f89a6f0113edd14b64bcd LockState-1.0.tar.gz
(55.49 KiB) Downloaded 539 times
LockState-0.1.tar.gz
MD5: 30c970f380aa93f74a779e9a0eb01c12 LockState-0.1.tar.gz
(93.2 KiB) Downloaded 491 times
LockState.png
(10.93 KiB) Downloaded 1170 times
Last edited by SFR on Fri 26 Apr 2019, 12:07, edited 9 times in total.
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

musher0
Posts: 14629
Joined: Mon 05 Jan 2009, 00:54
Location: Gatineau (Qc), Canada

#2 Post by musher0 »

Thanks, SFR.

Certainly useful for small WM's like aewm or echinus.

BFN.
musher0
~~~~~~~~~~
"You want it darker? We kill the flame." (L. Cohen)

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#3 Post by slavvo67 »

I would have never thought of something so simple, yet useful.

Thanks SFR!

Slavvo67

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#4 Post by vovchik »

Dear SFR,

Very nice and terse -- and useful. Thanks.

I had to change the makefile to:

Code: Select all

$(CC) lockstate.c -o lockstate $(FLAGS)  
to get it to compile because of newer and more fussy gcc.

With kind regards,
vovchik

PS. If you use inline svgs (or even inline pngs as header files), you could make this thing entirely self-contained. It would still be tiny, I think. :) I have attached some sample svgs that could be used as icons. They could be done in "inline" and written out to /tmp and read from there.

UPDATE: I modded your code slightly to include the inline svgs, which get written to /tmp and read from there. Seems to be working fine. :) The 6 svg strings could actually reduced to one, with some replacing (one #xxxx xx color for on/off and the char show for the key in <text></text>).
Attachments
lockstate-vov.c.tar.gz
(3.54 KiB) Downloaded 468 times
key-svg.tar.gz
(685 Bytes) Downloaded 551 times

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#5 Post by zigbert »

Very nice :)

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#6 Post by vovchik »

Dear SFR,

I did some code golfing and reduced the six svg inline strings to one and then implemented a search and replace routine to ready the svgs for export to /tmp. I think it's more tidy and efficient that way if using inline svgs. And, any old stock gtk icon could conceivably go into the desktop file, perhaps, obviating a need to put anything in /usr/share/pixmaps (only the desktop file itself in /usr/share/applications). What do you think

I have , in addition to the modded source, also included a 32-bit Tahr binary.

With kind regards,
vovchik
Attachments
lockstate-mod.c.tar.gz
(11.49 KiB) Downloaded 464 times

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#7 Post by SFR »

Thanks guys!

@Vovchik: yeah, I was hoping someone would provide "our own" icons. Many thanks for that! :D
The only changes I've made was to darken the inactive color from #bbbbbb to #888888, to get better contrast, and replaced the character for inactive state of ScrollLock from to .
It really looks nicer with your icons.

As for the code, since it's using GTK+ and friends anyway, I'm trying to limit myself to g_ stuff as much as possible, so I replaced what I could.
Makefile fixed as well.
vovchik wrote:I did some code golfing and reduced the six svg inline strings to one and then implemented a search and replace routine to ready the svgs for export to /tmp.
Thanks for the code, but I've already done it, not using any search/replace mechanisms, though.
Well, that was my first though, but I couldn't find an appropriate func in GLib, so just went a no-brainer way - divided one of the images into 3 sub-templates and glued them together with variables, in a loop.
But thanks for the search & replace routines, may come in handy one day.
vovchik wrote:any old stock gtk icon could conceivably go into the desktop file
I wanted to use a stock icon, but LxQtPanel can't display it in Menu (no wonder, it uses QT, not GTK), so I just used your caps-on instead, but converted to PNG, because the panel wasn't happy with SVG, too :roll: .

First post updated!

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#8 Post by vovchik »

Dear SFR,

It works very nicely and I'm glad I could be of some use. That search/replace function might indeed be useful elsehwere, but I can understand your desire to use gtk-related functions whenever possible. What is nice is that there are many ways the same problem can be solved with a bit of thinking. :) I wish politicians around the world would adopt the practice.

With kind regards,
vovchikl

User avatar
Puppus Dogfellow
Posts: 1667
Joined: Tue 08 Jan 2013, 01:39
Location: nyc

#9 Post by Puppus Dogfellow »

cool--seems to find the tray no matter where it's located. tested out the ability to attach shortcuts with the third mod in Rox and couldn't--second key didn't register no matter what non-modifier call i used. tried out meta and hyper and got control plus super and alt. tried it out in jwm and "3" as a key mask works fine. does anyone know how to get ISO_Level3_Shift working in puppy? Mode_shift works well (the file below uses it to put Menu on the q key--keyboard is missing menu and another i have is missing scroll_lock and menu, so this is the basic xmodfile i've been using:
! caps lock becomes mode switch, scroll lock becomes caps lock, Menu gets added as modeshift plus q
remove Lock = Caps_Lock
keycode 78 = Caps_Lock
! keycode 110 = Caps_Lock
keycode 66 = Mode_switch
add Lock = Caps_Lock
keycode 24 = q Q Menu Q q Q

! keycode 144 = Caps_Lock
! keycode 71 = F5
! keycode 72 = ISO_Level3_Shift
! keycode 153 = F6
! xmodmap -e 'keycode 21 = equal plus Menu'
! keycode 71 = Mode_switch Mode_switch Mode_switch Mode_switch
! keycode 49 = grave asciitilde grave asciitilde grave asciitilde
! keycode 9 = Escape Menu(second slot is plus shift) (plus modeshift)3 (plus shift and modeshift)4 (can't-get 5th6th2wrk)5 (iso level shift 3 plus shift)6
! possible use is to add another 24 function keys (12 on the Function row, 12 on the numbers plus -/+ row, so that shift isn't used/precluded as a modifier. getting isolevel to work would probably be a better solution...)

! (84 is 82 but with scroll lock rather than pause made caps lock; 87 is the same as 84 but without the menu key activated as mode shift plus q; all three relocate Caps_Lock and make the original key into Mode_switch
! c version makes caps lock an extra control and moves mode switch to pause (rest is same as 84))

! make Hyper_R the pause key and add it as a modifier:
keycode 110 = Hyper_R
add mod3 = Hyper_R
! add Control = Hyper_R
! ^tried the above to get the third modifier to work in rox to no avail. line doesn't affect whether or not mod3 works with jwm.
), and the hyper_R shortcut works well once you make jwm aware of it. thanks again and in advance :D

______

jwm mod3 template/includes file available.

User avatar
bigpup
Posts: 13886
Joined: Sun 11 Oct 2009, 18:15
Location: S.C. USA

#10 Post by bigpup »

This could be offered as a pet package to install.

You can still posts pet packages on the forum.
Just nothing bigger than Max size 256K.
Last edited by bigpup on Fri 14 Jul 2017, 16:02, edited 1 time in total.
The things they do not tell you, are usually the clue to solving the problem.
When I was a kid I wanted to be older.... This is not what I expected :shock:
YaPI(any iso installer)

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#11 Post by SFR »

@Puppus Dogfellow: glad it works for you and thanks for the feedback.
Unfortunately I can't help you with the other stuff, because I'm not sure what you're trying to achieve and how it relates to LockState.
___________
bigpup wrote:This could be offered as a pet package to install.
It is:
the opening post wrote:The attached archive contains source code, two PETs (for 32bit and 64bit systems) and TXZ package for Fatdog - all built in FD, too.
bigpup wrote:Max size 256mb.
I believe you meant 256kb.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#12 Post by SFR »

Version 0.4:
  • added Preferences dialog for colors & symbols customization
  • some internal rearrangements/improvements
First post updated.

Greetings!
Attachments
LockState_Settings.png
(22.31 KiB) Downloaded 812 times
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#13 Post by SFR »

Version 0.5:
  • added option to draw icons in reversed order (Scroll->Num->Caps), because some panels (JWM's, FBPanel...) draw tray icons from right to left
  • added 'Redraw icons' option
  • fixed some minor memory leaks
  • fixed segfault with glib < 2.36
  • small bugfix in sanity checks
  • code improvements
First post updated.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#14 Post by SFR »

Version 1.0:
  • left-clicking an icon toggles the state of the corresponding key
  • the last (hopefully) memory leak has been fixed
  • minor rearrangements in the code
That's pretty much all I wanted to implement/fix.

Fist post updated.

Greetings!
Last edited by SFR on Fri 14 Jul 2017, 20:31, edited 1 time in total.
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
bigpup
Posts: 13886
Joined: Sun 11 Oct 2009, 18:15
Location: S.C. USA

#15 Post by bigpup »

SFR wrote:
bigpup wrote:This could be offered as a pet package to install.
It is:
The first post looks like LockState-1.0.tar.gz is offered.
That is not a pet package.

I am talking about making a pet package of this, that you can download, click on, and it installs.

I know the pet is in the tar.gz package, but we are humans. :shock:
Keep it simple for the human mind. :lol:
The things they do not tell you, are usually the clue to solving the problem.
When I was a kid I wanted to be older.... This is not what I expected :shock:
YaPI(any iso installer)

User avatar
pp4mnklinux
Posts: 375
Joined: Fri 23 Aug 2013, 06:56

how to start it .... for newbies

#16 Post by pp4mnklinux »

https://howto1811.wordpress.com/2018/01 ... indicator/

I hope you find it useful


Have a nice day.
Distro: xenialpup64 7.5 XXL
Desktop Panel: JWM ~ FbBox 5.0

User avatar
spiritwild
Posts: 181
Joined: Mon 03 Oct 2016, 10:06

#17 Post by spiritwild »

niCe! Thanks.
This works well with xsetnumlock and numlocks too, although they are old programs they still serve a purpose if you want the numlock on at boot.

Might be a simple setting process now days, dunno.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#18 Post by SFR »

LockState-1.1:

- removed the micro-delay between displaying icons - it's no longer necessary with newer LxQt-Panel in Fatdog
- fixed quitting the app when Preferences window is open
- changed program icon

First post updated.

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

Post Reply