Skip to content

Commit

Permalink
x11: Improve code that auto-hides cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
andoma committed Sep 6, 2015
1 parent f8fba8a commit c62c10d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/ui/glw/glw.h
Expand Up @@ -52,6 +52,8 @@
#define NUM_CLIPPLANES 6
#define NUM_FADERS 6

#define GLW_CURSOR_AUTOHIDE_TIME 3000000

struct event;

typedef struct glw_style glw_style_t;
Expand Down
23 changes: 11 additions & 12 deletions src/ui/glw/glw_x11.c
Expand Up @@ -88,12 +88,12 @@ typedef struct glw_x11 {
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;

int fullwindow;
int autohide_counter;
int req_width;
int req_height;
int fixed_window_size;
int no_screensaver;

int64_t hide_cursor_at;

XIM im;
XIC ic;
Status status;
Expand Down Expand Up @@ -124,8 +124,6 @@ typedef struct glw_x11 {

} glw_x11_t;

#define AUTOHIDE_TIMEOUT 100 // XXX: in frames.. bad


/**
*
Expand Down Expand Up @@ -178,26 +176,28 @@ hide_cursor(glw_x11_t *gx11)
static void
autohide_cursor(glw_x11_t *gx11)
{
if(!gx11->fullwindow)
return;

if(gx11->cursor_hidden)
return;

if(gx11->autohide_counter == 0)
if(gx11->gr.gr_time_usec > gx11->hide_cursor_at) {
hide_cursor(gx11);
else if(gx11->gr.gr_pointer_grab == NULL)
gx11->autohide_counter--;
}
}


/**
*
*/
static void
show_cursor(glw_x11_t *gx11)
{
gx11->hide_cursor_at = gx11->gr.gr_time_usec + GLW_CURSOR_AUTOHIDE_TIME;
if(!gx11->cursor_hidden)
return;

gx11->autohide_counter = AUTOHIDE_TIMEOUT;
gx11->cursor_hidden = 0;
XUndefineCursor(gx11->display, gx11->win);
}
Expand Down Expand Up @@ -1002,9 +1002,8 @@ glw_x11_mainloop(glw_x11_t *gx11)

while(gx11->running) {

if(gx11->fullwindow)
autohide_cursor(gx11);

autohide_cursor(gx11);

if(gx11->wm_flags && !gx11->no_screensaver) {

if(gx11->fullwindow && gx11->sss == NULL)
Expand Down

0 comments on commit c62c10d

Please sign in to comment.