Compare commits
7 Commits
4572fe61bc
...
1ac6069bc4
Author | SHA1 | Date |
---|---|---|
|
1ac6069bc4 | |
|
2d8908a3f6 | |
|
24f146d240 | |
|
4196ff9565 | |
|
1abb33c18b | |
|
c87e4538b8 | |
|
818809d6e1 |
|
@ -66,8 +66,9 @@ struct CustomCursor {
|
|||
static CustomCursor * current_cursor;
|
||||
static CustomCursor * default_cursors[DEFOS_CURSOR_INTMAX];
|
||||
|
||||
static Cursor invisible_cursor;
|
||||
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,18 +96,9 @@ void defos_init()
|
|||
NET_FRAME_EXTENTS = XATOM("_NET_FRAME_EXTENTS");
|
||||
|
||||
resize_locked = false;
|
||||
|
||||
// Create invisible cursor
|
||||
Pixmap bitmapNoData;
|
||||
XColor black;
|
||||
static char noData[] = { 0,0,0,0,0,0,0,0 };
|
||||
black.red = black.green = black.blue = 0;
|
||||
|
||||
bitmapNoData = XCreateBitmapFromData(disp, win, noData, 8, 8);
|
||||
invisible_cursor = XCreatePixmapCursor(disp, bitmapNoData, bitmapNoData, &black, &black, 0, 0);
|
||||
XFreePixmap(disp, bitmapNoData);
|
||||
|
||||
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*));
|
||||
|
@ -114,7 +106,6 @@ void defos_init()
|
|||
|
||||
void defos_final()
|
||||
{
|
||||
XFreeCursor(disp, invisible_cursor);
|
||||
defos_gc_custom_cursor(current_cursor);
|
||||
for (int i = 0; i < DEFOS_CURSOR_INTMAX; i++) {
|
||||
defos_gc_custom_cursor(default_cursors[i]);
|
||||
|
@ -261,18 +252,29 @@ void defos_disable_window_resize()
|
|||
lock_resize(w, h);
|
||||
}
|
||||
|
||||
static void apply_cursor() {
|
||||
Cursor cursor = current_cursor ? current_cursor->cursor : None;
|
||||
XDefineCursor(disp, win, cursor);
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
XFixesHideCursor(disp, win);
|
||||
}
|
||||
XFlush(disp);
|
||||
}
|
||||
|
||||
void defos_set_cursor_visible(bool visible)
|
||||
{
|
||||
if (visible == is_cursor_visible) { return; }
|
||||
is_cursor_visible = visible;
|
||||
if (visible)
|
||||
{
|
||||
XFixesShowCursor(disp, win);
|
||||
XFlush(disp);
|
||||
} else {
|
||||
XFixesHideCursor(disp, win);
|
||||
XFlush(disp);
|
||||
}
|
||||
apply_cursor_visible();
|
||||
}
|
||||
|
||||
bool defos_is_cursor_visible()
|
||||
|
@ -502,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)
|
||||
|
@ -513,7 +523,7 @@ void * defos_load_cursor_linux(const char *filename)
|
|||
cursor->cursor = XcursorImageLoadCursor(disp, image);
|
||||
XcursorImageDestroy(image);
|
||||
} else {
|
||||
cursor->cursor = invisible_cursor;
|
||||
cursor->cursor = XCreateFontCursor(disp, XC_left_ptr);
|
||||
}
|
||||
cursor->ref_count = 1;
|
||||
return cursor;
|
||||
|
@ -532,13 +542,15 @@ void defos_gc_custom_cursor(void * _cursor)
|
|||
|
||||
void defos_set_custom_cursor(void * _cursor)
|
||||
{
|
||||
CustomCursor * old_cursor = current_cursor;
|
||||
|
||||
CustomCursor * cursor = (CustomCursor*)_cursor;
|
||||
cursor->ref_count += 1;
|
||||
|
||||
if (is_cursor_visible) { XDefineCursor(disp, win, cursor->cursor); }
|
||||
|
||||
defos_gc_custom_cursor(current_cursor);
|
||||
current_cursor = cursor;
|
||||
|
||||
apply_cursor();
|
||||
|
||||
defos_gc_custom_cursor(old_cursor);
|
||||
}
|
||||
|
||||
static unsigned int get_cursor(DefosCursor cursor);
|
||||
|
@ -557,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;
|
||||
}
|
||||
|
@ -823,6 +835,7 @@ char* defos_get_bundle_root()
|
|||
char* path = (char*)malloc(PATH_MAX + 2);
|
||||
ssize_t ret = readlink("/proc/self/exe", path, PATH_MAX + 2);
|
||||
if (ret >= 0 && ret <= PATH_MAX + 1) {
|
||||
path[ret] = '\0';
|
||||
result = copy_string(dirname(path));
|
||||
} else {
|
||||
const char* path2 = (const char*)getauxval(AT_EXECFN);
|
||||
|
|
Loading…
Reference in New Issue