[Solved] How to make an autostarted program follow desktop focus?

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
gostal
Level 3
Level 3
Posts: 119
Joined: Fri Sep 07, 2018 9:56 am

[Solved] How to make an autostarted program follow desktop focus?

Post by gostal »

It's no problem to make an application window follow desktop focus, i.e, the window goes to the new desktop if you switch to another. A few mouse klicks and it's done.

But, how do I set this in the application's .desktop file which resides in the autostart folder?

Cheers,
gostal
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Lap: Latitude E6520, i3-2330M @ 2.20GHz, 4GB, Intel HD Graphics 3000, OS Mint 19.1 version Mate, Windows 7 Enterprise
Desk: Dell Precision T5810, Xeon E5-1650 v4 @ 3.60GHz,72 GB, Radeon Pro WX 7100, OS CentOS 7.7
Stockholm, Sweden
gostal
Level 3
Level 3
Posts: 119
Joined: Fri Sep 07, 2018 9:56 am

Re: How to make an autostarted program follow desktop focus?

Post by gostal »

To be precise I am autostarting xosview and I would like to have it follow my workspace/desktop switches without the series of mouse klicks. Can this be accomplished in Mate?

cheers,
gostal
Lap: Latitude E6520, i3-2330M @ 2.20GHz, 4GB, Intel HD Graphics 3000, OS Mint 19.1 version Mate, Windows 7 Enterprise
Desk: Dell Precision T5810, Xeon E5-1650 v4 @ 3.60GHz,72 GB, Radeon Pro WX 7100, OS CentOS 7.7
Stockholm, Sweden
gm10

Re: How to make an autostarted program follow desktop focus?

Post by gm10 »

gostal wrote: Thu Oct 24, 2019 1:19 pm To be precise I am autostarting xosview and I would like to have it follow my workspace/desktop switches without the series of mouse klicks. Can this be accomplished in Mate?
If you're using the compiz window manager then you can configure this is compiz' window rules, but for a solution that will work with most window managers and applications, replace the command in your autostart entry with this:

Code: Select all

bash -c 'xosview & for w in $(xdotool search --sync --onlyvisible --class xosview);do wmctrl -b toggle,sticky -ir $w;done'
PS: I have no idea what the post above mine has got to do with anything...
gostal
Level 3
Level 3
Posts: 119
Joined: Fri Sep 07, 2018 9:56 am

Re: How to make an autostarted program follow desktop focus?

Post by gostal »

gm10 wrote: Tue Oct 29, 2019 7:05 am ...

Code: Select all

bash -c 'xosview & for w in $(xdotool search --sync --onlyvisible --class xosview);do wmctrl -b toggle,sticky -ir $w;done'
Wow! Thanks! It would have taken me ages to come up with that.
gm10 wrote: Tue Oct 29, 2019 7:05 am PS: I have no idea what the post above mine has got to do with anything...
Same here. The autostarting in itself was never the problem ...

Cheers,
gostal
Lap: Latitude E6520, i3-2330M @ 2.20GHz, 4GB, Intel HD Graphics 3000, OS Mint 19.1 version Mate, Windows 7 Enterprise
Desk: Dell Precision T5810, Xeon E5-1650 v4 @ 3.60GHz,72 GB, Radeon Pro WX 7100, OS CentOS 7.7
Stockholm, Sweden
gm10

Re: How to make an autostarted program follow desktop focus?

Post by gm10 »

No problem, happy to help.
gostal wrote: Wed Oct 30, 2019 6:05 am
gm10 wrote: Tue Oct 29, 2019 7:05 am PS: I have no idea what the post above mine has got to do with anything...
Same here. The autostarting in itself was never the problem ...
Actually I've looked up his posting history, it's mostly off-topic, some is even about Windows. Usually that means it's a bot with marketing links getting edited in later and/or added to the signature, but the posting pattern does not quite match. Maybe they improved the software. :lol:
gostal
Level 3
Level 3
Posts: 119
Joined: Fri Sep 07, 2018 9:56 am

Re: [Solved] How to make an autostarted program follow desktop focus?

Post by gostal »

@gm10

I haven't tried your neat command tweak for the .desktop-file on my laptop yet but I just did on my desktop which now after many years running various OpenSuse releases is running CentOS 7.7. A definite change for the better compared to Leap 15.0 which I don't miss at all. So much was broken there and Mate too! I filed a bug report regarding broken menu in Mate and the maintainer confirmed but said he wouldn't bother since it was about 4000 lines of code. Not the response I had hoped for so I buttered and begged on my knees. Eventually the maintainer gave in and two days later send me a patch that worked. Then he goes ahead and requests that the patch be accepted for Leap 15.1 leaving 15.0 to its' fate. Leap 15.0 didn't last very long on my desktop. I upgraded because during the last half year or so with Leap 42.3 the OS had deteriorated to the point where only failsafe boot would work and I was sick and tired of that. Well, the upgrade finished without any quirks but on reboot I could no longer log in at all. I had two users, one local and one LDAP authenticated plus root and none of them could log in, in any manner. It turned out that the upgrade had messed up the PAM config files so that the lines in them were written in the wrong order which had the effect that if LDAP authentication failed then local authentication did not come in to play. LDAP failed because the server was running LDAP ver. 2 and updates had replaced the ver. 2 client with a ver. 3 one which then expected a ver. 3 server unless told otherwise. Took me the better part of a week to figure these things out and eventually get to the point where I could log in to the system. This craziness gave rise to the first bug report with Leap 15.0 but more were to follow.

Sorry to spill out my frustration like this. I hope you have forbearance.

Now to the issue: At first it didn't work. xosview showed up alright but it didn't follow desktop focus. Then I took a closer look at your command line and realised that xdotool is a program. Did I have it? No, so I installed it and learned that it basically allows you to do various mouse operations on the command line. Very clever. This is what's behind your statement that this method should work for most window managers and applications. And of course it worked in my new CentOS desktop sporting Mate 1.16. So cool! And I have no fears whatsoever regarding my Mint laptop. Thanks again, not only for the case in point but also for boosting my Linux knowledge.

Cheers,
gostal
Lap: Latitude E6520, i3-2330M @ 2.20GHz, 4GB, Intel HD Graphics 3000, OS Mint 19.1 version Mate, Windows 7 Enterprise
Desk: Dell Precision T5810, Xeon E5-1650 v4 @ 3.60GHz,72 GB, Radeon Pro WX 7100, OS CentOS 7.7
Stockholm, Sweden
gm10

Re: [Solved] How to make an autostarted program follow desktop focus?

Post by gm10 »

gostal wrote: Thu Oct 31, 2019 11:51 am xdotool is a program. Did I have it? No
My apologies, I had mistakenly thought it was pre-installed on Mint. I could have given you a solution without using that program, but it would have been slightly longer.
gostal wrote: Thu Oct 31, 2019 11:51 am This is what's behind your statement that this method should work for most window managers and applications.
Actually xdotool in that command is just used to collect the ids of all the windows created by programs with that name and more importantly wait for at least one such window to get created in the first place, which is important here since you're only just starting the program you are interested in.

With "most window managers" I meant the wmctrl command, which implements _NET_WM_STATE_STICKY, which is part of freedesktop's standard for window managers to make windows sticky: https://standards.freedesktop.org/wm-sp ... 0472615568. Just like xdotool, it's a convenience function, you could also have set the hint directly via xprop. "most", because not all window managers (fully) implement that standard.

With "most ... applications" I meant that I have the command loop through all windows of the same class, so this generally also works with applications opening multiple windows (although timing can become an issue here because xdotool will only wait for the first window to get shown).

Just some details since you seem interested. :)
gostal wrote: Thu Oct 31, 2019 11:51 am And of course it worked in my new CentOS desktop sporting Mate 1.16. So cool! And I have no fears whatsoever regarding my Mint laptop. Thanks again, not only for the case in point but also for boosting my Linux knowledge.
You're quite welcome. Responding to you from my MATE 1.23.2 desktop, for it currently is my desktop of choice as well. ;)
gostal
Level 3
Level 3
Posts: 119
Joined: Fri Sep 07, 2018 9:56 am

Re: [Solved] How to make an autostarted program follow desktop focus?

Post by gostal »

gm10 wrote: Thu Oct 31, 2019 12:34 pm
Just some details since you seem interested. :)
Of course I'm interested and your clarification is most welcome! The lines in the xdotool manpage that made me write what I did are these:
xdotool lets you programatically (or manually) simulate keyboard input and mouse activity,
move and resize windows, etc. It does this using X11's XTEST extension and other Xlib
functions.
My first thought was that you can programmatically move the mouse to the correct location and perform the mentioned mouse clicks but I realise that is not what's going on in your command line. It looks like it is theoretically possible, however, but it would involve more steps. Your method is far better using wmctrl to control the window's sticky state. Are there any more cool window managing tools that I should now about?

And why do I run CentOS when I could run Mint, you may wonder. Well, there are two reasons. One is because I can get support from our computer support guys and the other is that have to run a commercial FEA software which is compiled for RHEL. I have tried running the software on Ubuntu (the other OS that the support guys support) and spent the better part of a day creating symlinks because libs where in the wrong place and had the wrong name and installing dependencies from elsewhere since they could not be found in the Ubuntu repos ... but to no avail and this tells me that Mint wont be a solution either. I had to put in symlinks in OpenSuse too but that was all it took. in CentOS, though, the sotfware runs out of the box. After having run CentOS now for about a month and a half I do believe it is a good OS. You may not get the latest and the greatest but what you do get works with the exception of TeXLive if you have to deal with Swedish, like me. The system GCC is pretty old, too, but the latest version of GSL compiled just fine so I don't expect any issues there.

Cheers,
gostal
Lap: Latitude E6520, i3-2330M @ 2.20GHz, 4GB, Intel HD Graphics 3000, OS Mint 19.1 version Mate, Windows 7 Enterprise
Desk: Dell Precision T5810, Xeon E5-1650 v4 @ 3.60GHz,72 GB, Radeon Pro WX 7100, OS CentOS 7.7
Stockholm, Sweden
gm10

Re: [Solved] How to make an autostarted program follow desktop focus?

Post by gm10 »

gostal wrote: Fri Nov 01, 2019 10:47 am And why do I run CentOS when I could run Mint, you may wonder. Well, there are two reasons. One is because I can get support from our computer support guys
Couldn't/shouldn't you have asked them the question here then? ;)

Regarding software built for another platform, your best solution is usually to rebuild from source for your platform instead of trying to make it fit with symlinks and such. I don't know if your vendor makes the source code available though.

And sure, there's a number of tools that allow window manipulation, one low level tool I had mentioned above is xprop.
gostal
Level 3
Level 3
Posts: 119
Joined: Fri Sep 07, 2018 9:56 am

Re: [Solved] How to make an autostarted program follow desktop focus?

Post by gostal »

gm10 wrote: Fri Nov 01, 2019 12:23 pm Couldn't/shouldn't you have asked them the question here then? ;)
I asked in this forum because I've got Mint on my laptop and the problem originated there. Besides, the CentOS fora are nowhere near as active. ;)
gm10 wrote: Fri Nov 01, 2019 12:23 pm Regarding software built for another platform, your best solution is usually to rebuild from source for your platform instead of trying to make it fit with symlinks and such. I don't know if your vendor makes the source code available though.
No, the source code is proprietary so rebuilding is not an option and the vendor is sometimes hard pressed for support because we choose other OS-s than the one they support. Believe me, I would run Mint on my desktop if could because so far it's one of the best Linux experiences I've had. Clearly better than the mother distro. :) Perhaps I can persuade our support guys to go Mint instead of Ubuntu. There are more Mint lovers here, not just me.

Cheers,
gostal
Lap: Latitude E6520, i3-2330M @ 2.20GHz, 4GB, Intel HD Graphics 3000, OS Mint 19.1 version Mate, Windows 7 Enterprise
Desk: Dell Precision T5810, Xeon E5-1650 v4 @ 3.60GHz,72 GB, Radeon Pro WX 7100, OS CentOS 7.7
Stockholm, Sweden
Locked

Return to “MATE”