Commit 0f42e8eb authored by deuce's avatar deuce
Browse files

Add mousepointer() function to set the mouse pointer type.

parent e673eb2c
......@@ -247,6 +247,7 @@ static int try_x_init(int mode)
cio_api.set_modepalette=bitmap_set_modepalette;
cio_api.map_rgb = bitmap_map_rgb;
cio_api.replace_font = bitmap_replace_font;
cio_api.mousepointer=x_mousepointer;
return(1);
}
return(0);
......@@ -1923,3 +1924,13 @@ int main(int argc, char **argv)
return ma.ret;
}
#endif
/* Returns non-zero on success */
CIOLIBEXPORT uint32_t CIOLIBCALL ciolib_mousepointer(enum ciolib_mouse_ptr type)
{
CIOLIB_INIT();
if (cio_api.mousepointer)
return cio_api.mousepointer(type);
return 0;
}
......
......@@ -86,6 +86,11 @@ enum {
,CIOLIB_MODE_SDL_FULLSCREEN
};
enum ciolib_mouse_ptr {
CIOLIB_MOUSEPTR_ARROW
,CIOLIB_MOUSEPTR_BAR
};
#if defined(_WIN32) /* presumably, Win32 */
#include <io.h> /* isatty */
......@@ -340,6 +345,7 @@ typedef struct {
int (*ungetmouse) (struct mouse_event *mevent);
int (*hidemouse) (void);
int (*showmouse) (void);
int (*mousepointer) (enum ciolib_mouse_ptr);
void (*settitle) (const char *);
void (*setname) (const char *);
void (*seticon) (const void *, unsigned long);
......@@ -427,6 +433,7 @@ CIOLIBEXPORT void CIOLIBCALL ciolib_setname(const char *title);
CIOLIBEXPORT void CIOLIBCALL ciolib_seticon(const void *icon,unsigned long size);
CIOLIBEXPORT int CIOLIBCALL ciolib_showmouse(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_hidemouse(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_mousepointeer(enum ciolib_mouse_ptr);
CIOLIBEXPORT void CIOLIBCALL ciolib_copytext(const char *text, size_t buflen);
CIOLIBEXPORT char * CIOLIBCALL ciolib_getcliptext(void);
CIOLIBEXPORT int CIOLIBCALL ciolib_setfont(int font, int force, int font_num);
......@@ -508,6 +515,7 @@ CIOLIBEXPORT void CIOLIBCALL ansi_ciolib_setdoorway(int enable);
#define ungetmouse(a) ciolib_ungetmouse(a)
#define hidemouse() ciolib_hidemouse()
#define showmouse() ciolib_showmouse()
#define mousepointer(a) ciolib_mousepointer(a)
#define setname(a) ciolib_setname(a)
#define seticon(a,b) ciolib_seticon(a,b)
#define settitle(a) ciolib_settitle(a)
......@@ -653,6 +661,7 @@ CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_addevents(uint64_t events);
CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_delevents(uint64_t events);
CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_addevent(uint64_t event);
CIOLIBEXPORT uint64_t CIOLIBCALL ciomouse_delevent(uint64_t event);
CIOLIBEXPORT uint32_t CIOLIBCALL ciolib_mousepointer(enum ciolib_mouse_ptr type);
#ifdef __cplusplus
}
#endif
......
......@@ -447,6 +447,18 @@ int x_init(void)
xp_dlclose(dl);
return(-1);
}
if((x11.XCreateFontCursor=xp_dlsym(dl,XCreateFontCursor))==NULL) {
xp_dlclose(dl);
return(-1);
}
if((x11.XDefineCursor=xp_dlsym(dl,XDefineCursor))==NULL) {
xp_dlclose(dl);
return(-1);
}
if((x11.XFreeCursor=xp_dlsym(dl,XFreeCursor))==NULL) {
xp_dlclose(dl);
return(-1);
}
setlocale(LC_ALL, "");
x11.XSetLocaleModifiers("@im=none");
......@@ -531,3 +543,16 @@ int x_getscaling(void)
{
return x_cvstat.scaling;
}
int x_mousepointer(enum ciolib_mouse_ptr type)
{
struct x11_local_event ev = {0};
ev.type=X11_LOCAL_MOUSEPOINTER;
if(x11_initialized) {
ev.data.ptr=type;
write_event(&ev);
return 1;
}
return 0;
}
......@@ -76,6 +76,7 @@ void x11_flush(void);
void x_setscaling(int newval);
int x_getscaling(void);
void x_seticon(const void *icon, unsigned long size);
int x_mousepointer(enum ciolib_mouse_ptr type);
#ifdef __cplusplus
}
#endif
......
......@@ -15,6 +15,7 @@
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>
#include <threadwrap.h>
#include <genwrap.h>
......@@ -66,6 +67,7 @@ static Atom WM_DELETE_WINDOW=0;
static Display *dpy=NULL;
static Window win;
static Cursor curs = None;
static Visual visual;
static XImage *xim;
static XIM im;
......@@ -1199,6 +1201,27 @@ void x11_event_thread(void *args)
free(lev.data.icon_data);
break;
}
case X11_LOCAL_MOUSEPOINTER: {
unsigned shape = UINT_MAX;
Cursor oc = curs;
switch (lev.data.ptr) {
case CIOLIB_MOUSEPTR_ARROW:
// Use default
break;
case CIOLIB_MOUSEPTR_BAR:
shape = XC_xterm;
break;
}
if (shape == UINT_MAX)
x11.XDefineCursor(dpy, win, None);
else {
curs = x11.XCreateFontCursor(dpy, shape);
x11.XDefineCursor(dpy, win, curs);
}
if (oc != None && oc != curs)
x11.XFreeCursor(dpy, oc);
break;
}
}
}
}
......
......@@ -17,6 +17,7 @@ enum x11_local_events {
,X11_LOCAL_FLUSH
,X11_LOCAL_BEEP
,X11_LOCAL_SETICON
,X11_LOCAL_MOUSEPOINTER
};
struct x11_local_event {
......@@ -27,6 +28,7 @@ struct x11_local_event {
char title[81];
struct rectlist *rect;
unsigned long *icon_data;
enum ciolib_mouse_ptr ptr;
} data;
};
......@@ -91,6 +93,9 @@ struct x11 {
int (*XwcLookupString)(XIC ic, XKeyPressedEvent *event, wchar_t *buffer_return, int wchars_buffer, KeySym *keysym_return, Status *status_return);
void (*XSetICFocus)(XIC ic);
Bool (*XFilterEvent)(XEvent *event, Window w);
Cursor (*XCreateFontCursor)(Display *display, unsigned int shape);
int (*XDefineCursor)(Display *display, Window w, Cursor cursor);
int (*XFreeCursor)(Display *display, Cursor cursor);
Atom utf8;
Atom targets;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment