Show cursor again when window not in focus
parent
24f146d240
commit
2d8908a3f6
|
@ -67,6 +67,8 @@ static CustomCursor * current_cursor;
|
|||
static CustomCursor * default_cursors[DEFOS_CURSOR_INTMAX];
|
||||
|
||||
static bool is_cursor_visible = true;
|
||||
static bool is_cursor_actually_visible = true;
|
||||
static bool window_has_focus = true;
|
||||
static bool resize_locked = false;
|
||||
|
||||
static bool is_window_visible(Window window);
|
||||
|
@ -95,6 +97,8 @@ void defos_init()
|
|||
|
||||
resize_locked = false;
|
||||
is_cursor_visible = true;
|
||||
is_cursor_actually_visible = true;
|
||||
window_has_focus = true;
|
||||
|
||||
current_cursor = NULL;
|
||||
memset(default_cursors, 0, DEFOS_CURSOR_INTMAX * sizeof(CustomCursor*));
|
||||
|
@ -253,10 +257,10 @@ static void apply_cursor() {
|
|||
XDefineCursor(disp, win, cursor);
|
||||
}
|
||||
|
||||
void defos_set_cursor_visible(bool visible)
|
||||
{
|
||||
if (visible == is_cursor_visible) { return; }
|
||||
is_cursor_visible = visible;
|
||||
static void apply_cursor_visible() {
|
||||
bool visible = is_cursor_visible || !window_has_focus;
|
||||
if (visible == is_cursor_actually_visible) { return; }
|
||||
is_cursor_actually_visible = visible;
|
||||
|
||||
if (visible) {
|
||||
XFixesShowCursor(disp, win);
|
||||
|
@ -266,6 +270,13 @@ void defos_set_cursor_visible(bool visible)
|
|||
XFlush(disp);
|
||||
}
|
||||
|
||||
void defos_set_cursor_visible(bool visible)
|
||||
{
|
||||
if (visible == is_cursor_visible) { return; }
|
||||
is_cursor_visible = visible;
|
||||
apply_cursor_visible();
|
||||
}
|
||||
|
||||
bool defos_is_cursor_visible()
|
||||
{
|
||||
return is_cursor_visible;
|
||||
|
@ -493,6 +504,14 @@ bool defos_is_cursor_locked()
|
|||
|
||||
void defos_update()
|
||||
{
|
||||
Window focused_window;
|
||||
int revert_to;
|
||||
if (!XGetInputFocus(disp, &focused_window, &revert_to)) {
|
||||
focused_window = None;
|
||||
}
|
||||
|
||||
window_has_focus = focused_window == win;
|
||||
apply_cursor_visible();
|
||||
}
|
||||
|
||||
void * defos_load_cursor_linux(const char *filename)
|
||||
|
@ -550,7 +569,7 @@ void defos_set_cursor(DefosCursor cursor_type)
|
|||
|
||||
void defos_reset_cursor()
|
||||
{
|
||||
if (is_cursor_visible) { XUndefineCursor(disp, win); }
|
||||
XUndefineCursor(disp, win);
|
||||
defos_gc_custom_cursor(current_cursor);
|
||||
current_cursor = NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue