Skip to content
Snippets Groups Projects
Commit d25c649b authored by deuce's avatar deuce
Browse files

Implement seticon() for X11 (finally)

parent a3ddb26e
No related branches found
No related tags found
No related merge requests found
......@@ -242,6 +242,7 @@ static int try_x_init(int mode)
cio_api.get_window_info=x_get_window_info;
cio_api.setscaling=x_setscaling;
cio_api.getscaling=x_getscaling;
cio_api.seticon=x_seticon;
cio_api.setpalette=bitmap_setpalette;
cio_api.attr2palette=bitmap_attr2palette;
cio_api.setpixel=bitmap_setpixel;
......
......@@ -128,6 +128,23 @@ void x_settitle(const char *title)
write_event(&ev);
}
void x_seticon(const void *icon, unsigned long size)
{
const uint32_t *icon32 = icon;
struct x11_local_event ev;
int i;
ev.data.icon_data = malloc((size*size + 2)*sizeof(ev.data.icon_data[0]));
if (ev.data.icon_data != NULL) {
ev.type=X11_LOCAL_SETICON;
for (i = 0; i < size*size; i++)
ev.data.icon_data[i + 2] = ((icon32[i] & 0xff000000))|((icon32[i] & 0x00ff0000) >> 16)|((icon32[i] & 0x0000ff00))|((icon32[i] & 0x000000ff)<<16);
ev.data.icon_data[0] = size;
ev.data.icon_data[1] = size;
write_event(&ev);
}
}
void x_copytext(const char *text, size_t buflen)
{
struct x11_local_event ev;
......@@ -397,6 +414,10 @@ int x_init(void)
xp_dlclose(dl);
return(-1);
}
if((x11.XAllocClassHint=xp_dlsym(dl,XAllocClassHint))==NULL) {
xp_dlclose(dl);
return(-1);
}
if(sem_init(&pastebuf_set, 0, 0)) {
xp_dlclose(dl);
......
......@@ -75,6 +75,7 @@ void x11_drawrect(struct rectlist *data);
void x11_flush(void);
void x_setscaling(int newval);
int x_getscaling(void);
void x_seticon(const void *icon, unsigned long size);
#ifdef __cplusplus
}
#endif
......
......@@ -241,6 +241,7 @@ static int init_window()
XGCValues gcv;
int i;
XWMHints *wmhints;
XClassHint *classhints;
int ret;
int best=-1;
int best_depth=0;
......@@ -295,13 +296,19 @@ static int init_window()
win = x11.XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0,
640*x_cvstat.scaling, 400*x_cvstat.scaling*x_cvstat.vmultiplier, 2, depth, InputOutput, &visual, CWColormap | CWBorderPixel | CWBackPixel, &wa);
classhints=x11.XAllocClassHint();
if (classhints)
classhints->res_name = classhints->res_class = "CIOLIB";
wmhints=x11.XAllocWMHints();
if(wmhints) {
wmhints->initial_state=NormalState;
wmhints->flags = (StateHint | IconPixmapHint | IconMaskHint | InputHint);
wmhints->flags = (StateHint/* | IconPixmapHint | IconMaskHint*/ | InputHint);
wmhints->input = True;
x11.XSetWMProperties(dpy, win, NULL, NULL, 0, 0, NULL, wmhints, NULL);
x11.XSetWMProperties(dpy, win, NULL, NULL, 0, 0, NULL, wmhints, classhints);
x11.XFree(wmhints);
}
if (classhints)
x11.XFree(classhints);
WM_DELETE_WINDOW = x11.XInternAtom(dpy, "WM_DELETE_WINDOW", False);
......@@ -1096,6 +1103,15 @@ void x11_event_thread(void *args)
case X11_LOCAL_BEEP:
x11.XBell(dpy, 100);
break;
case X11_LOCAL_SETICON: {
Atom wmicon = x11.XInternAtom(dpy, "_NET_WM_ICON", False);
if (wmicon) {
x11.XChangeProperty(dpy, win, wmicon, XA_CARDINAL, 32, PropModeReplace, (unsigned char *)lev.data.icon_data, lev.data.icon_data[0] * lev.data.icon_data[1] + 2);
x11.XFlush(dpy);
}
free(lev.data.icon_data);
break;
}
}
}
}
......
......@@ -15,6 +15,7 @@ enum x11_local_events {
,X11_LOCAL_DRAWRECT
,X11_LOCAL_FLUSH
,X11_LOCAL_BEEP
,X11_LOCAL_SETICON
};
struct x11_local_event {
......@@ -24,6 +25,7 @@ struct x11_local_event {
char name[81];
char title[81];
struct rectlist *rect;
unsigned long *icon_data;
} data;
};
......@@ -80,6 +82,7 @@ struct x11 {
Window (*XCreateWindow)(Display *display, Window parent, int x, int y, unsigned int width, unsigned int height, unsigned int border_width, int depth,
unsigned int class, Visual *visual, unsigned long valuemask, XSetWindowAttributes *attributes);
Colormap (*XCreateColormap)(Display *display, Window w, Visual *visual, int alloc);
XClassHint *(*XAllocClassHint)(void);
Atom utf8;
Atom targets;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment