LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-15-2017, 12:16 PM   #1
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Popping up new window without focus... how to do it?


I have a reminder system that I wrote a while back that plays an audio file and pops up a window--using xmessage(1)--based on other shell scripts, crontab entries, etc. While it works rather well, it has one rather annoying side effect: the popped up window takes input focus away from whatever the user is currently doing. Anyone getting one of these notices that's doing any kind of text entry (coding, writing test, etc.) loses some work when the notices pops up until they manually reset input focus to the editor or browser.

Is there a way to have xmessage open a window but not grab input focus? I've done some searching in the manpages and found nothing that appears to control that. While I might be able to modify the way that the window manager deals with new windows--KDE is my preferred but I'm hoping for a solution that is agnostic with respect to WM--I'm afraid that such a change would affect all windows; something I definitely want to avoid.

Any ideas?

TIA...

--
Rick

Last edited by rnturn; 03-15-2017 at 12:23 PM.
 
Old 03-15-2017, 02:50 PM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Could you try using gxmessage instead? It has the following option:

Quote:
-nofocus
Prevents the gxmessage window from receiving focus when it
opens. This option is not compatible with xmessage.
 
Old 03-15-2017, 03:33 PM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
maybe you should use "notify-send" instead???
 
Old 03-15-2017, 04:01 PM   #4
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Original Poster
Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by hydrurga View Post
Could you try using gxmessage instead?
Maybe except I cannot find it on the system or using any repository searches in YaST. I assume this is a GTK version of xmessage and that would work. If I can find an RPM for it. (Or, if I'm feeling adventurous and want to try and build it from sources.)
 
Old 03-15-2017, 04:15 PM   #5
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Original Poster
Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by ondoho View Post
maybe you should use "notify-send" instead???
That's sort of nifty but in addition to using it for "Weekly conference call in 5 minutes"-type messages, I also use xmessage within scripts and like that it's interactive and let's me set the exit status so I can branch accord to whatever button was clicked on; notify-send doesn't appear to allow that. One other thing I like about xmessage is the ability to run it and specify a big obnoxious font size. I haven't figured out how one does that with notify-send yet. Or if it's even possible.
 
Old 03-15-2017, 04:29 PM   #6
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
Quote:
Originally Posted by rnturn View Post
Maybe except I cannot find it on the system or using any repository searches in YaST. I assume this is a GTK version of xmessage and that would work. If I can find an RPM for it. (Or, if I'm feeling adventurous and want to try and build it from sources.)
Any of these do you?

https://www.rpmfind.net/linux/rpm2ht...uery=gxmessage
 
Old 03-16-2017, 02:11 AM   #7
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Quote:
Originally Posted by rnturn View Post
That's sort of nifty but in addition to using it for "Weekly conference call in 5 minutes"-type messages, I also use xmessage within scripts and like that it's interactive and let's me set the exit status so I can branch accord to whatever button was clicked on; notify-send doesn't appear to allow that.
well it's either that, or no focus.
i fail to understand how you can both
- not have focus
- demand user input
???

Quote:
One other thing I like about xmessage is the ability to run it and specify a big obnoxious font size. I haven't figured out how one does that with notify-send yet. Or if it's even possible.
it is possible, depending on the actual notification daemon.
i use dunst as my notification daemon, and it is definitely possible with that.
other popular choices are: xfce4-notifyd, deepin-notifications, lxqt-notificationd, mate-notification-daemon, notify-osd etc.
 
Old 03-16-2017, 03:39 AM   #8
camp0
Member
 
Registered: Dec 2016
Location: Dublin
Distribution: Fedora
Posts: 70

Rep: Reputation: 4
Here is another option in python

Code:
from gi.repository import Notify
Notify.init("App Name")
Notify.Notification.new("Hi").show()
 
Old 03-16-2017, 04:59 AM   #9
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
xmessage itself doesn't take focus: in fact you'll find most normal Xlib applications are passive with regard to focus because focus stealing is considered bad behaviour. You can confirm this yourself if you start X with something like xinit /usr/bin/xterm from a tty instead of starting X the usual way and then running xmessage without a window manager present.

A program may set the 'Input field' of WM_HINTS to let the window manager know whether or not it needs or expects input focus (things like xload/xclock set this to 'false') but I'm afraid xmessage doesn't provide an option for setting this and it's entirely down to the window manager to decide whether to give focus to a window or not when it is mapped and as such that is where you'll have to look to see if you can configure it not to do this to xmessage's window.

Last edited by GazL; 03-16-2017 at 05:07 AM.
 
Old 03-16-2017, 09:22 AM   #10
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Original Poster
Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by hydrurga View Post
Ah. My googling may have found that but it must have been farther down in the findings. The higher rated links weren't all that promising. I'll give that a shot. Thx...
 
Old 03-16-2017, 09:31 AM   #11
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Original Poster
Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by GazL View Post
xmessage itself doesn't take focus: in fact you'll find most normal Xlib applications are passive with regard to focus because focus stealing is considered bad behaviour. You can confirm this yourself if you start X with something like xinit /usr/bin/xterm from a tty instead of starting X the usual way and then running xmessage without a window manager present.
Good point. I have started up X manually like that for a lo-o-ong time. I do recall that behaviour.

Quote:
A program may set the 'Input field' of WM_HINTS to let the window manager know whether or not it needs or expects input focus (things like xload/xclock set this to 'false') but I'm afraid xmessage doesn't provide an option for setting this and it's entirely down to the window manager to decide whether to give focus to a window or not when it is mapped and as such that is where you'll have to look to see if you can configure it not to do this to xmessage's window.
Interesting. (I'm guessing that you must have some some low-level X11 programming in the past.) So manipulating WM_HINTS must be the big feature that drove the development of gxmessage?

Another responder reminded me of an RPM finder site--that I haven't visited for ages--that looks like it has an RPM for gxmessage. Guess I've gotten too comfortable with the typical SuSE repositories; they usually have everything I need.

Thanks for the info...
 
Old 03-16-2017, 11:19 AM   #12
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Original Poster
Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by ondoho View Post
well it's either that, or no focus.
i fail to understand how you can both
- not have focus
- demand user input
???
Windows can open but not take over the keyboard. What I'm looking for is for the window to pop up and wait for the user to select it.
 
Old 03-16-2017, 11:31 AM   #13
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Original Poster
Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Got it!

"hydrurga"'s suggestion of gxmessage did the trick. (Thanks.)

I found no RPMs--or SRPMs--that were built for OpenSUSE 13.2 but did find an old 2.6.0 SRPM for SUSE 9. That built against without error (w/ couple of warnings) but seems to run OK. Well, except that the window size did not auto adjust to the length of the message. Eventually I tracked down an newer SRPM (v3.4.3). That works even better. I do find it a little funky that it doesn't accept X11 font naming and one script had to change the font name from "-*-fixed-*-*-*-*-*-400-*-*-*-*-*-*" to something like "Adobe Courier 40" but that's not really a problem though it makes it not quite a drop-in replacement for xmessage.

Marking this one solved.

Thanks to all who offered suggestions.

Later, guys...
 
Old 03-16-2017, 12:21 PM   #14
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018Reputation: 5018
Quote:
Originally Posted by rnturn View Post
I'm guessing that you must have some some low-level X11 programming in the past
Nah, I just like to read the manuals and dabble with things. I've got the basics of Xlib down, little more than that.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
strange behavior, window popping up in black lab linux geraldw3210 Linux - Newbie 2 08-26-2015 08:48 AM
focus on vlc window maspai Linux - Software 1 07-25-2012 01:37 AM
Changing window focus / cursor locked in window Linear_z Linux - Desktop 2 09-24-2011 12:40 PM
Gnome window focus jackpal Linux - Desktop 1 12-23-2009 12:34 PM
window focus thaprza Linux - Newbie 3 03-06-2005 03:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:53 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration