LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-06-2014, 10:07 AM   #1
prushik
Member
 
Registered: Mar 2009
Location: Pennsylvania
Distribution: gentoo
Posts: 372

Rep: Reputation: 29
X Events from other (all) windows


Hi everybody,
I wrote a program which is basically just a fullscreen clock. It looks great and I am really happy with it. I intend to use it as sort of a screensaver, so I wrote it to be compatible with xscreensaver and I got that working. However, the problem is that xscreensaver kills it whenever there is mouse or keyboard activity. I want it to shut off when the mouse is moved, but I want it to keep running when keys are pressed because I want to use the keyboard to switch between some different options in the program (different clock styles).
So, I have been thinking of other solutions (besides xscreensaver). There aren't a lot (or any) other screensaver daemons available besides xscreensaver, so I think I should write my own. Nothing too complicated, just something that waits until the machine is idle and then starts up a program. However, to check if the machine is idle, I would need to be able to get mouse events from all windows simultaneously, which I am not sure how to do, and I can't find any documentation online about how to do something like that. I would like to use XCB or XLib.

Anybody know where I could start, or does anybody know of another screensaver program that will allow me to continue running after a keypress?

Thanks!

p.s. Sorry if this is the wrong place to ask, its kind of a hybrid question though and it relates to Linux Software so thats where I am posting it.


EDIT: Found how to get events from everything. http://www.google.co.kr/url?sa=t&rct...0nPcSvgOUa1Ajg

Anyways, if anybody has a better solution than me writing my own screensaver program, that would be cool!

Last edited by prushik; 03-06-2014 at 10:57 AM. Reason: Better info / refine question
 
Old 03-10-2014, 01:23 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
The problem with writing your own screensaver is that the keyboard is used for security functions - entering a password to unlock.

Thus you don't want anything/anyone to tamper with it. Any time you allow a bypass of that function, you risk having the screensaver terminate in inappropriate ways.... or being unable to enter the password, and unlock.
 
Old 03-10-2014, 09:59 AM   #3
prushik
Member
 
Registered: Mar 2009
Location: Pennsylvania
Distribution: gentoo
Posts: 372

Original Poster
Rep: Reputation: 29
Quote:
Originally Posted by jpollard View Post
The problem with writing your own screensaver is that the keyboard is used for security functions - entering a password to unlock.

Thus you don't want anything/anyone to tamper with it. Any time you allow a bypass of that function, you risk having the screensaver terminate in inappropriate ways.... or being unable to enter the password, and unlock.
That's true, although I am not really that afraid of breaking the rules a little bit. I personally never use screen locking and find it annoying on my single-user system. The purpose of the screensaver clock is actually my raspberry pi wearable computer that I built with a 1.8 inch screen attached to a watch band (so when I'm not using it, it looks like a watch). However, I plan to use it on my personal computer too once I add an alarm clock function. The screensaver will probably show up after only a minute or two of sitting idle, so I don't want to have the screen lock all the time, especially since nobody else can use a computer I am wearing, I think its a little bit extraneous.

What I think I meant when I asked the question was actually about a replacement for the xscreensaver daemon. I had a look at the source code for xscreensaver and I think right now I am working on just writing my own from scratch, the xscreensaver code is commented pretty well (though filled with obscenities, mainly because of weird things X does) and easy to read, I successfully converted some of the basic parts of it into XCB, but I ran into a strange issue with XCB not selecting new windows properly, although I am convinced that my XCB code is equivalent to the xscreensaver Xlib code. I think I will be able to work around the problem for now (until I figure out what I am doing wrong) using the actual Xorg screensaver extension (which xscreensaver should use also, but doesn't seem to on my system, even though its available).

When I am done with it I will release my code if anybody is interested.
 
Old 03-10-2014, 10:08 AM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Replacing the daemon is trivial - just change the reference to the utility.

But it is no longer a lock - but a screen "blanking" feature. All you have to do is disable dpms (which does the normal blanking) and have the application do a Xserver keyboard grab. The only time this is blocked is by certain keyboard based applications (usually account related) to prevent interposing events...

The usual problem with this is that the first key entry (which stops the blanking) gets lost. It is possible to pass on the event.. but a number of utilities don't accept interposed keyboard events.

Such applications then just open a window (without decoration) the size of the root window, thus covering all other windows.

One thing you can think about is whether to direct a window manager to unmap all other windows - this should allow the X server to dump the displays (reclaiming the memory) and provide better response. When the blanking is done, it then direct applications to remap the display (it does have to record what windows are active at the start of the blanking though).

Last edited by jpollard; 03-10-2014 at 10:12 AM.
 
Old 03-10-2014, 10:39 AM   #5
prushik
Member
 
Registered: Mar 2009
Location: Pennsylvania
Distribution: gentoo
Posts: 372

Original Poster
Rep: Reputation: 29
Quote:
Originally Posted by jpollard View Post
Replacing the daemon is trivial - just change the reference to the utility.

But it is no longer a lock - but a screen "blanking" feature. All you have to do is disable dpms (which does the normal blanking) and have the application do a Xserver keyboard grab. The only time this is blocked is by certain keyboard based applications (usually account related) to prevent interposing events...
Right, I am not interested in locking. However, I think I will implement dpms in my program to switch of the display after a while in order to reduce power usage. I am unsure why I would have to do a keyboard grab though, do you mean to prevent xscreensaver from detecting the keyboard as activity? For now I am planning to completely do away with xscreensaver and use the xorg mit-screensaver extension instead, in that case I can control everything including when to shut down my screensaver.


Quote:
Originally Posted by jpollard View Post
The usual problem with this is that the first key entry (which stops the blanking) gets lost. It is possible to pass on the event.. but a number of utilities don't accept interposed keyboard events.

Such applications then just open a window (without decoration) the size of the root window, thus covering all other windows.
That is basically what my screensaver does now. I'm not sure what you mean about losing a keypress though, but I am not sure why I would need to grab the keyboard either.


Quote:
Originally Posted by jpollard View Post
One thing you can think about is whether to direct a window manager to unmap all other windows - this should allow the X server to dump the displays (reclaiming the memory) and provide better response. When the blanking is done, it then direct applications to remap the display (it does have to record what windows are active at the start of the blanking though).
That's a good idea, I don't see how it helps improve response though, wouldn't it take time for the WM to remap the windows?
 
Old 03-10-2014, 01:10 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,908

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by prushik View Post
That is basically what my screensaver does now. I'm not sure what you mean about losing a keypress though, but I am not sure why I would need to grab the keyboard either.
You might not have to grab the keyboard since all events would get sent to the application with the top level open window. The "lost keypress" is sent to the top level application, so none of the covered applications will get it.


Quote:
That's a good idea, I don't see how it helps improve response though, wouldn't it take time for the WM to remap the windows?
The response would be for your clock, not the covered windows. In either case, the applications supplying the data for those windows will get an even to redraw them anyway. Its just a thought. I have worked with window managers that do unmapping/mapping events (see ctwm... a nice window manager - I extended it from a maximum of 32 workspaces to allow for a compile time option for the number of workspaces).
 
Old 03-10-2014, 01:34 PM   #7
prushik
Member
 
Registered: Mar 2009
Location: Pennsylvania
Distribution: gentoo
Posts: 372

Original Poster
Rep: Reputation: 29
Quote:
Originally Posted by jpollard View Post
You might not have to grab the keyboard since all events would get sent to the application with the top level open window. The "lost keypress" is sent to the top level application, so none of the covered applications will get it.
Well, my application would be the top level window, so that would be what I want, right? Although what I really want is _all_ keypresses to get "lost" in my application until I decide to close it.



Quote:
Originally Posted by jpollard View Post
The response would be for your clock, not the covered windows. In either case, the applications supplying the data for those windows will get an even to redraw them anyway. Its just a thought. I have worked with window managers that do unmapping/mapping events (see ctwm... a nice window manager - I extended it from a maximum of 32 workspaces to allow for a compile time option for the number of workspaces).
Right, although I doubt that my response time would suffer at all with such a tiny program, its always good to save resources.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
fetch Windows events using Samba 3.3.2 alterego201 Linux - Newbie 0 04-21-2009 08:48 AM
Hang on triggering udev events- is there a buildup of events? sonichedgehog Slackware 20 07-11-2008 03:49 AM
How to capture Windows API Events sridhar_dct3 Linux - Software 1 10-18-2007 10:48 AM
Capture Windows Events erat123 Programming 1 07-05-2007 12:10 PM
What is the equivalent of Windows events in Linux DavidW567 Programming 8 12-24-2004 06:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:28 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