X Selection-Clear D-Bus Service and Cinnamon applet.

About programming and getting involved with Linux Mint development
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

X Selection-Clear D-Bus Service and Cinnamon applet.

Post by rene »

[EDIT] Note: please check the later/last post of this thread first: it's an ongoing development.

Topic continued from viewtopic.php?p=1590195#p1590195 but moved from the Newbie section to what comes closest to a programming section...
majpooper wrote: Mon Feb 04, 2019 3:30 pm A Cinnamon applet would be awesome (but huge amount of work) - setting the interval now I know how is easy - 10sec was a bit short, 60sec is working but just a tad too long maybe - I will probably experiment until I find the optimum time. But I can imagine situations where pause/resume would be ideal as there are times when copy/paste big files and editing clearing the clipboard so soon may be a problem or just wanting to set the interval on the fly.
So, that was actually a fair amount of fun. The former systemd user daemon is now a D-Bus service complete with a Cinnamon applet to control it. The applet needs fairly current Cinnamon, i.e., Mint 19.x or LMDE3, seeing as how there was a major upgrade to the Cinnamon JavaScript engine between Mint 18/LMDE2 and now, providing for much nicer syntax.

Previously one had to start the daemon explicitly but the way this now works is that the applet autostarts it simply by contacting it over D-Bus. I.e., nothing to do except install it. I've also made a basic .deb package for it so you can install and remove it easily.

The applet once added to your panel betrays its current clearing period by hovering over it with the mouse, allows for disabling/enabling the automatic clearing and provides for manual clearing from its left-click menu, and can be set to be enabled on startup and have its clearing period set from its right-click "Configure" menu.

To install, please first uninstall the v0.1 version you installed:

Code: Select all

$ systemctl --user stop xselcd.service
$ sudo rm /etc/xdg/autostart/xselcd.desktop /etc/systemd/user/xselcd.service /usr/local/bin/xselcd
Then unpack the attached xselc-0.2.tar.gz in e.g. your home directory. To compile you will need:

Code: Select all

sudo apt-get install build-essential libx11-dev libglib2.0-dev
Former two as before, latter as new. Then

Code: Select all

$ cd ~/xselc-2.0
$ make deb
$ sudo dpkg -i xselc_0.2-1_amd64.deb
and add the applet to your panel with right-click Panel -> Add applets to panel -> X Selection-Clear D-Bus Service. That should be all there's to it; was tested both on Mint 19.1 and LMDE 3. To remove it again, remove the applet from your panel and run sudo dpkg -r xselc.

Was a fair amount of fun to "design" a D-Bus service, and with the in Mint 19.x / LMDE3 newly available JavaScript syntax the applet turned out nice as well. There's quotes around "design" since as D-Bus services go, this one is extremely minimal, and may as such presumably function as a template for interested readers. Investigating all this newfangled infrastructure is what I myself got from it anyway; hope the thing itself is useful to you.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 3 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by rene »

One comment by the way is...

When you clear selections a selection in e.g. the terminal is also unhighlighted, providing for visual feedback. Firefox for example does however not do this: the selection is still cleared (i.e., you can't copy it any more) but in Firefox selected text is not automatically unhighlighted. I've tried investigating methods to have Firefox do so but have not found any: not anything I did on the X side made Firefox unhighlight the selection, and I'm at this point not certain one can do so externally.

Mostly just an aesthetic thing but would've been good to get going. If I still find out how to have e.g. Firefox pay attention I'll update...
User avatar
majpooper
Level 8
Level 8
Posts: 2084
Joined: Thu May 09, 2013 1:56 pm
Location: North Carolina, USA

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by majpooper »

HOOOAH! outstanding -this is exactly the solution that was needed - easy to use and works perfectly.
I have been playing with editing the xselcd.service to get different timings to clear the clipboard depending on the task at hand and it cumbersome. This applet is a lot better than having to edit -t N parameter in /etc/systemd/user/xselcd.service and restarting the service. The Enable on start-up button is a nice touch - for me it will always be on but makes the applet configurable. Also the left click function takes the place of needing to configure a keyboard shortcut - I really like this feature and the hover to display the clipboard clearing time.

You really covered every detail and it was well executed.

THX so much this is way more than I could have imagined.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by rene »

Good to know it's deemed useful. Selection clearing I personally don't need but I do expect I might make variants of this for other wants. The setup with a D-Bus service for the actual work and a controlling applet is fairly nice,
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by rene »

Failed to mention it before but the version above potentially overshoots by one period. I.e., if you select something just after the daemon woke up it won't yet be a period old when it wakes one period later, will only be cleared two periods later. Had planned on looking into fixing that properly later but got myself lost in the D-Bus and applet methodology.

Just remembered and had some time to look but it seems it's not actually possible to fix this properly: haven't found a way to get X to (reliably) give up the time a selection was last set/changed. Especially with the limit for this thing being set at 5 whole minutes, overshooting a whole period is rather lame though. I.e., attached is a version 0.3 that just wakes up every second instead, limiting overshoot to just under said second. Given that it does hardly anything anyway that's not in fact an issue.

If you don't care about the potential overshoot feel free to not upgrade but if you do: remove applet from panel, sudo dpkg -r xselc to uninstall, and reinstall with from the newly unpacked sources

Code: Select all

$ make deb
$ sudo dpkg -i xselc_0.3-1_amd64.deb
Ctrl-Alt-Esc to restart Cinnamon --- I don't know why that would be neccesary, but something terribly funky is going on Cinnamon-sides in regards to unwarranted caching -- and add applet to the panel again.
User avatar
majpooper
Level 8
Level 8
Posts: 2084
Joined: Thu May 09, 2013 1:56 pm
Location: North Carolina, USA

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by majpooper »

Good catch - hadn't even noticed any "period overshoot" but but an upgrade is easy enough and will install 0.3 on new installs when 19.3 finally arrives.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by rene »

I was contacted by an interested Manjaro Cinnamon user and added Arch package support for a version v0.4, as attached to this post. There are no functional changes from v0.3. Installation instructions:

1. If upgrading from a previous version first remove the current applet by rightclicking it and choosing "Remove 'X Selection-Clear D-Bus Service'".

2. Mint 19.x needs a few build dependencies:

Code: Select all

sudo apt-get install build-essential libx11-dev libglib2.0-dev
Manjaro Cinnamon 18.0.4 has everything OOTB.

3. Unpack the downloaded source archive:

Code: Select all

$ tar xvzf ~/Downloads/xselc-0.4.tar.gz
$ cd xselc-0.4
4. On Debian-based distributions:

Code: Select all

$ make deb
$ sudo dpkg -i xselc_0.4-1_amd64.deb
On Arch-based ones:

Code: Select all

$ make pkg
$ sudo pacman -U xselc-0.4-1-x86_64.pkg.tar.xz
5. Add the applet to the panel by right-clicking the panel -> Add applets to panel -> X Selection-Clear D-Bus Service.

6. To use, leftclick the applet to en/disable periodic clearing or to clear selections now, and rightclick -> Configure to have it enable at startup and to set the clearing period.

Not a Manjaro user, but the thing seemingly works well on both Mint 19.x and Manjaro 18.0.4 Cinnamon 64-bit, upgraded as of the date of posting. Hope it's useful; comments welcome, preferably as replies in this thread.
Attachments
xselc-0.4.tar.gz
(4.51 KiB) Downloaded 172 times
n0ne

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by n0ne »

Thx Rene, this is awesome & very nice of you! Great update, very much appreciated!
User avatar
majpooper
Level 8
Level 8
Posts: 2084
Joined: Thu May 09, 2013 1:56 pm
Location: North Carolina, USA

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by majpooper »

rene wrote: Fri Aug 16, 2019 6:34 am I was contacted by an interested Manjaro Cinnamon user and added Arch package support for a version v0.4, as attached to this post. There are no functional changes from v0.3. Installation instructions:

Not a Manjaro user, but the thing seemingly works well on both Mint 19.x and Manjaro 18.0.4 Cinnamon 64-bit, upgraded as of the date of posting. Hope it's useful; comments welcome, preferably as replies in this thread.
Ditto THX much rene from me as well - and yes it is working flawlessly on Mint 19.2 Cinnamon.
prostyler

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by prostyler »

On mint 20:

Code: Select all

xselc.c:13:10: fatal error: gio/gio.h: No such file or directory
   13 | #include <gio/gio.h>
      |          ^~~~~~~~~~~
compilation terminated.
+

Code: Select all

dpkg: error: cannot access archive 'xselc_0.4-1_amd64.deb': No such file or directory
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by rene »

You missed or something went wrong at step 2.
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by rene »

When switching to Linux Mint 20.1 I noticed that the by xselc used Mint 19 Mint-Y panel-icon 'clipboard' is no longer supplied; the hereby updated version 0.5 packages said icon alongside. No other changes.

1. If upgrading from a previous version first remove the current applet by rightclicking it and choosing "Remove 'X Selection-Clear D-Bus Service'".

2. Mint 19.x, Mint 20.x, LMDE3, LMDE4 and LMDE5 need a few build dependencies:

Code: Select all

sudo apt-get install build-essential libx11-dev libglib2.0-dev
majpooper recently noticed that on plain Debian additionally the fakeroot package needs to be installed. The tested Manjaro Cinnamon 18.0.4 and 21.0.4 have everything OOTB.

3. Unpack the to this message attached source archive:

Code: Select all

$ tar xvzf ~/Downloads/xselc-0.5.tar.gz
$ cd xselc-0.5
4. On Debian-based distributions:

Code: Select all

$ make deb
$ sudo dpkg -i xselc_0.5-1_amd64.deb
On Arch-based ones:

Code: Select all

$ make pkg
$ sudo pacman -U xselc-0.5-1-x86_64.pkg.tar.xz
5. Add the applet to the panel by right-clicking the panel -> Add applets to panel -> X Selection-Clear D-Bus Service.

6. To use, leftclick the applet to en/disable periodic clearing or to clear selections now, and rightclick -> Configure to have it enable at startup and to set the clearing period.
Attachments
xselc-0.5.tar.gz
(5.56 KiB) Downloaded 104 times
Last edited by rene on Sat May 21, 2022 6:28 pm, edited 2 times in total.
JBTR
Level 1
Level 1
Posts: 4
Joined: Mon Jul 12, 2021 8:43 pm
Location: USA - Illinois

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by JBTR »

Thank you rene.
I found this on a search, installed it on 20.1, and it seems to be working just fine.
You have made a very important contribution to Linux Mint!
- - -
John
miw2n
Level 1
Level 1
Posts: 22
Joined: Tue Sep 28, 2021 11:49 am

Re: X Selection-Clear D-Bus Service and Cinnamon applet.

Post by miw2n »

I have been using it for last 6 months and it is working just fine.

It is one of my faviourite programs. It is exactly what I needed- to clear clipboard but with additional settings like timer, one click On/Off, adjustable timer based on user preference and needs. It is an applet, so the settings are at 'hands reach'.

I have not checked the source code (I am not a dev), but I am trusting that it is not privacy harming (spyware) based on the level or trustworthiness of the dev (it is highest level-20).

Excellent work.
Locked

Return to “Programming & Development”