Mousecorner version 0.0.8 ========================= A program to react to the mouse being left in the corner of the screen, basically by turning the screensaver on, for X Windows in general and for jwz's XScreenSaver (http://www.jwz.org/xscreensaver) in particular. It is written in two parts, a daemon, mousecorner, and a shell-script, mousecorner-command. mousecorner daemon ------------------ Usage: mousecorner [-h] [-v] [-r ] [-s ] [-t ] -h - prints a short help message and exits -v - prints version and exits -r - sets range (size of sensitive corner) to value between 0 and 16, default is 4 -s - number of seconds to sleep for, between 1 and 9, default is 2. -t - number of times daemon must catch a mouse in a corner to trigger action, default is 2, range is from 1 to 9. On startup, mousecorner does all the proper Unixische daemon stuff described in the Unix Programmer FAQ (1.7) (http://www.faqs.org/faqs/unix-faq/programmer/faq/) ie it forks, setsids, forks again (so it has no controlling terminal), sets a umask of 0, chdir's to "/" (so it doesn't hang onto any directories if stuff needs unmounting) closes all open file descriptors and sets stdin and stdout to /dev/null, so don't expect to hear much from it. By default it sets stderr to /dev/null too, but if you want to hear from it, edit mousecorner.h and set MOUSECORNER_LOG to something like /tmp/mousecorner-log instead. Once suitably forked off, not attached to terminals and properly in the background, the mousecorner 'daemon' goes into an infinite loop doing the following: - It sleeps most of the time. - Every 2 seconds (or whatever value was set with -s), it wakes up and does this: 1 - Establish where the corners of the screen are (this may have changed since we were last woken.) 2 - Establish if the mouse is at any of the corners 3 - If it is so, increment the counter for that corner 4 - If the counter is exactly 2 times (or whatever was set with -t), activate the appropriate command (via the shellscript) for that corner. 5 - Cleans up after itself The size of the sensitive bits of the corners defaults to 4 (and can be reset with -r), so you can still use it even if, like me, you use Enlightenment or another window manager where hitting a corner may also mean sliding to another virtual window. mousecorner-command ------------------- The shell-script, mousecorner-command, which has a long name for a short script, and which can, and should, even, be used to turn mousecorner on and off, with, um, mousecorner-command (on|off). The script should be used to invoke mousecorner since it kills all running instances of mousecorner before starting another one. There is nothing in mousecorner itself to stop multiple versions of itself running, but it's unlikely to be a good idea. The script can also be called with parameters 'tl', 'tr', 'bl', 'br', for the four corners of the screen, and will invoke an action as appropriate. This is, in fact, what the daemon does when it decides you've left your mouse in the corner for long enough to trigger an action. By default, the script either activates XScreenSaver or locks the screen with XScreenSaver, but you can edit it to taste as you wish. In this way, you can alter the behaviour of the 'hot' mouse corners without having to recompile the daemon. Security -------- Since calling mousecorner-command will turn your screensaver on, you might want to do a chmod 0700 and a chown you:you on the script to make sure that only processes running as you can do it. For now I've left it at the default permission set given by automake's install target, since I'm not sure that it makes any difference - in fact I'm still not wholly sure that it wouldn't be safer to have the actions compiled into the daemon. After all, if someone is maliciously running programs as you, you already have worse problems than whether or not they activate your screensaver, so the permissions thing may be moot. I'd appreciate any comments or ideas people might have about this. Including 'Omigod. How stupid is that,' if it turns out to be a stupid thing to do to run mousecorner at all the way it is currently written. I've written it because, as much as other may not like this functionality, I've realised I do, so I'd like to get it right, and don't intend to call it 0.1 until I'm reasonably sure I've got the right approach. Then I've got to get *that* right. Etc. Meanwhile, please be aware that mousecorner is a program that will run all the time with the specific purpose of occasionally executing arbitrary commands, ostensibly the ones you want, as specified in the mousecorner-command script, but potentially anything, if that script should ever be changed. This makes it an inherent security risk and I would not recommend running mousecorner without being aware of such, and erring on the side of caution if you are unsure whether or not the risk is worth it. Install ------- Install is, or should be, ./configure, make, make install. If not, please let me know. That's it. TODO ---- - Make it run smaller and lighter. Half a meg to check the position of the mouse every two seconds seems excessive. (This became 192K after running for a while, but on restarting, became half a meg again. Hrm.) - Think about responding to other signals than SIGINT - perhaps implement a 'make sure only one of us runs' restart on USR1 - Listen for screen size change events and only recalculate screen size on them. - Look for a way of getting the mouse position directly from the root window without having to allocate dummy window pointers and wasting memory. - Audit properly for security. Wayne Myers, 12th May, 2002, waz@easynet.co.uk