2

I am currently using Linux Mint 19.03 Cinnamon.

Issue

I launch gnome-calculator with Cal shortcut button and when I press that button, new gnome-calculator window is spawned. I don't want this behaviour. enter image description here

Expected result

I am expecting the Cal button launches gnome-calculator but if it is already running, when Cal is pressed again, it will reveal the existing window, and so on and so forth.

Current attempt

I've found, using dconf editor that I can customize the desktop.
So far, I've also found the string to execute the gnome-calculator which is:

org.cinnamon.desktop.default-applications.calculator exec 'gnome-calculator'

I use dconf editor such as this one: enter image description here

So far, what I need is to change the Custom value with the proper command to check the existing calculator window and reveal it.

The question

What is the command (or script too) to focus on existing gnome-calculator window? And if it doesn't exist, simply spawn one.

Thank you in advance.

2
  • I am not an expert and I have never had this thought, thus I never dig in it; anyway I would take a look at 1) wmctrl utility, and 2) GTK options. – mattia.b89 May 1 '20 at 15:49
  • @mattia.b89 thank you for wmctrl suggestion. I've posted an answer myself. please help to validate the answer. – Jastria Rahmat May 2 '20 at 6:08
3

I've found the answer. This problem turns out not a specific DE problem. It's the behavior of the app itself which is gnome-calculator.

I've found two methods(or workarounds) for doing this:

Using wmctrl

So, the basic command is this:

wmctrl -xa gnome-calculator || gnome-calculator

To make it work in dconf command, warp it in shell command and apply it to dconf using terminal such as this:

gsettings set org.cinnamon.desktop.default-applications.calculator exec "sh -c 'wmctrl -xa gnome-calculator || gnome-calculator'"

Using xdotool

With this one,you need to installxdotool.

The command:

xdotool search --class gnome-calculator windowactivate || gnome-calculator

Dconf setting:

gsettings set org.cinnamon.desktop.default-applications.calculator exec "sh -c 'xdotool search --class gnome-calculator windowactivate || gnome-calculator'"

reference:
mattia-b89's comment
askubuntu question
mtwebster's github comment

2
  • I appreciate this workaround, but I wonder if it's true that the problem is the behavior of the app itself. I've noticed all my "launch app" buttons have the same behavior (launch email, launch browser, launch settings, launch calculator, etc.). Whereas when I launch any of them from the GNOME shell, it does what I'd expect: it focuses on the existing window, if there is one. – mmaluff Jul 14 '20 at 5:50
  • 1
    @mmaluff its according to this post, They leave the app to decide it's behavior. – Jastria Rahmat Jul 14 '20 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.