aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <yalhcru@gmail.com>2020-05-19 01:49:22 -0400
committerB. Watson <yalhcru@gmail.com>2020-05-19 01:49:22 -0400
commit7f81b16f333b034953c25be7148657552a7da783 (patch)
tree68211031c109abc943eac18c6b50e265164cef50
parent005fc7dcf69fc112b5ce3d2c4017769cd8e425e8 (diff)
downloadunsaver-7f81b16f333b034953c25be7148657552a7da783.tar.gz
use correct root window
-rw-r--r--jsmond.c50
1 files changed, 38 insertions, 12 deletions
diff --git a/jsmond.c b/jsmond.c
index 643287d..a7b8d40 100644
--- a/jsmond.c
+++ b/jsmond.c
@@ -38,12 +38,15 @@
/* command for -x */
#define X_COMMAND "xscreensaver-command -deactivate"
+/* default "-i 250ms" */
+#define DEFAULT_INTERVAL 250
+
typedef enum {
fm_auto_keycode, fm_keycode, fm_button, fm_motion, fm_cmd
} fake_mode_t;
/* user options */
-int interval = 250; /* -i (always in millisec) */
+int interval = DEFAULT_INTERVAL; /* -i (always in millisec) */
int debug = 0; /* -D */
int keycode = -1; /* -k */
int button = -1; /* -b */
@@ -287,32 +290,55 @@ int get_joystick_activity(void) {
return active;
}
+/* supposedly we could use the X window property _NET_WINDOW_FULLSCREEN
+ to detect a fullscreen window, but not everything actually sets that.
+ so a fullscreen window is defined here as:
+ - visible
+ - is the size of the root window
+ - and has input focus.
+*/
int have_fullscreen_window(void) {
Window w;
XWindowAttributes w_attrs, root_attrs;
int revert_to;
- /* TODO: error check? */
- XGetInputFocus(xdisp, &w, &revert_to);
+ /* man page doesn't document the actual
+ return value, it says "int", is it really a Status? */
+ if(!XGetInputFocus(xdisp, &w, &revert_to)) {
+ if(debug) fprintf(stderr, "XGetInputFocus() failed\n");
+ return 0;
+ }
+
+ /* no window has focus (not an error) */
+ if(w == None)
+ return 0;
+
+ /* TODO: under what conditions does this fail? if it does fail once,
+ will it ever succeed again?
- if(w != None) {
- XGetWindowAttributes(xdisp, DefaultRootWindow(xdisp), &root_attrs);
- XGetWindowAttributes(xdisp, w, &w_attrs);
+ Hopefully, using w_attrs.root will do the right thing in multi-screen
+ environments. I can't easily test it though. */
+ if( XGetWindowAttributes(xdisp, w, &w_attrs) &&
+ XGetWindowAttributes(xdisp, w_attrs.root, &root_attrs) )
+ {
- /*
- fprintf(stderr, "window id %d has focus, geometry %dx%d\n",
- (int)w, w_attrs.width, w_attrs.height);
- */
+ if(debug)
+ fprintf(stderr,
+ "window id 0x%x (root 0x%x) has focus, map_state %d, geometry %dx%d\n",
+ (int)w, (int)w_attrs.root, w_attrs.map_state, w_attrs.width, w_attrs.height);
if( (w_attrs.map_state == IsViewable) &&
- (root_attrs.width == w_attrs.width) &&
- (root_attrs.height == w_attrs.height) )
+ (root_attrs.width == w_attrs.width) &&
+ (root_attrs.height == w_attrs.height) )
{
if(debug) fprintf(stderr,
"window id 0x%x has input focus and looks fullscreen (%dx%d)\n",
(int)w, w_attrs.width, w_attrs.height);
return 1;
}
+ } else if(debug) {
+ if(debug) fprintf(stderr, "XGetWindowAttributes() failed\n");
+ return 0;
}
return 0;