Skip to content
Snippets Groups Projects
Commit 8a9fc05b authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Add initial icon settings.

Also, set both _NET_WM_ICON and WMHint icon pixmap
parent 2714bdd5
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4377 passed
...@@ -90,6 +90,8 @@ CIOLIBEXPORT int ciolib_initial_window_width = -1; ...@@ -90,6 +90,8 @@ CIOLIBEXPORT int ciolib_initial_window_width = -1;
CIOLIBEXPORT double ciolib_initial_scaling = 0; CIOLIBEXPORT double ciolib_initial_scaling = 0;
CIOLIBEXPORT int ciolib_initial_mode = C80; CIOLIBEXPORT int ciolib_initial_mode = C80;
CIOLIBEXPORT enum ciolib_scaling ciolib_initial_scaling_type = CIOLIB_SCALING_INTERNAL; CIOLIBEXPORT enum ciolib_scaling ciolib_initial_scaling_type = CIOLIB_SCALING_INTERNAL;
CIOLIBEXPORT const void * ciolib_initial_icon = syncicon64;
CIOLIBEXPORT size_t ciolib_initial_icon_width = 64;
CIOLIBEXPORT const uint32_t *ciolib_r2yptr; CIOLIBEXPORT const uint32_t *ciolib_r2yptr;
CIOLIBEXPORT const uint32_t *ciolib_y2rptr; CIOLIBEXPORT const uint32_t *ciolib_y2rptr;
......
...@@ -417,6 +417,8 @@ CIOLIBEXPORTVAR int ciolib_initial_window_width; ...@@ -417,6 +417,8 @@ CIOLIBEXPORTVAR int ciolib_initial_window_width;
CIOLIBEXPORTVAR double ciolib_initial_scaling; CIOLIBEXPORTVAR double ciolib_initial_scaling;
CIOLIBEXPORTVAR int ciolib_initial_mode; CIOLIBEXPORTVAR int ciolib_initial_mode;
CIOLIBEXPORTVAR enum ciolib_scaling ciolib_initial_scaling_type; CIOLIBEXPORTVAR enum ciolib_scaling ciolib_initial_scaling_type;
CIOLIBEXPORTVAR const void * ciolib_initial_icon;
CIOLIBEXPORTVAR size_t ciolib_initial_icon_width;
CIOLIBEXPORTVAR const uint32_t *ciolib_r2yptr; CIOLIBEXPORTVAR const uint32_t *ciolib_r2yptr;
CIOLIBEXPORTVAR const uint32_t *ciolib_y2rptr; CIOLIBEXPORTVAR const uint32_t *ciolib_y2rptr;
......
...@@ -408,6 +408,84 @@ static void map_window() ...@@ -408,6 +408,84 @@ static void map_window()
return; return;
} }
static void
set_icon(const void *data, size_t width, XWMHints *hints)
{
const uint32_t *idata = data;
Pixmap opm = icn;
Pixmap opmm = icn_mask;
XGCValues gcv = {
.function = GXcopy,
.foreground = black | 0xff000000,
.background = white
};
int x,y,i;
GC igc, imgc;
bool fail = false;
unsigned short tmp;
XColor fg;
bool sethints = (hints != NULL);
icn = x11.XCreatePixmap(dpy, DefaultRootWindow(dpy), width, width, depth);
igc = x11.XCreateGC(dpy, icn, GCFunction | GCForeground | GCBackground | GCGraphicsExposures, &gcv);
icn_mask = x11.XCreatePixmap(dpy, DefaultRootWindow(dpy), width, width, 1);
imgc = x11.XCreateGC(dpy, icn_mask, GCFunction | GCForeground | GCBackground | GCGraphicsExposures, &gcv);
fail = (!icn) || (!icn_mask);
if (!fail) {
for (x = 0, i = 0; x < width; x++) {
for (y = 0; y < width; y++) {
if (idata[i] & 0xff000000) {
tmp = (idata[i] & 0xff);
fg.red = tmp << 8 | tmp;
tmp = (idata[i] & 0xff00) >> 8;
fg.green = tmp << 8 | tmp;
tmp = (idata[i] & 0xff0000) >> 16;
fg.blue = tmp << 8 | tmp;
fg.flags = DoRed | DoGreen | DoBlue;
if (x11.XAllocColor(dpy, wincmap, &fg) == 0)
fail = true;
else {
x11.XSetForeground(dpy, igc, fg.pixel);
x11.XDrawPoint(dpy, icn, igc, y, x);
x11.XSetForeground(dpy, imgc, white);
x11.XDrawPoint(dpy, icn_mask, imgc, y, x);
}
if (fail)
break;
}
else {
x11.XSetForeground(dpy, imgc, black);
x11.XDrawPoint(dpy, icn_mask, imgc, y, x);
}
i++;
}
if (fail)
break;
}
}
if (!fail) {
if (!hints)
hints = x11.XGetWMHints(dpy, win);
if (!hints)
hints = x11.XAllocWMHints();
if (hints) {
hints->flags |= IconPixmapHint | IconMaskHint;
hints->icon_pixmap = icn;
hints->icon_mask = icn_mask;
if (sethints) {
x11.XSetWMHints(dpy, win, hints);
x11.XFree(hints);
}
if (opm)
x11.XFreePixmap(dpy, opm);
if (opmm)
x11.XFreePixmap(dpy, opmm);
}
}
x11.XFreeGC(dpy, igc);
x11.XFreeGC(dpy, imgc);
}
/* Get a connection to the X server and create the window. */ /* Get a connection to the X server and create the window. */
static int init_window() static int init_window()
{ {
...@@ -479,10 +557,12 @@ static int init_window() ...@@ -479,10 +557,12 @@ static int init_window()
if (classhints) if (classhints)
classhints->res_name = classhints->res_class = "CIOLIB"; classhints->res_name = classhints->res_class = "CIOLIB";
wmhints=x11.XAllocWMHints(); wmhints=x11.XAllocWMHints();
wmhints->flags = 0;
if(wmhints) { if(wmhints) {
wmhints->initial_state=NormalState; wmhints->initial_state=NormalState;
wmhints->flags = (StateHint/* | IconPixmapHint | IconMaskHint*/ | InputHint); wmhints->flags |= (StateHint | InputHint);
wmhints->input = True; wmhints->input = True;
set_icon(ciolib_initial_icon, ciolib_initial_icon_width, wmhints);
x11.XSetWMProperties(dpy, win, NULL, NULL, 0, 0, NULL, wmhints, classhints); x11.XSetWMProperties(dpy, win, NULL, NULL, 0, 0, NULL, wmhints, classhints);
x11.XFree(wmhints); x11.XFree(wmhints);
} }
...@@ -1537,82 +1617,15 @@ void x11_event_thread(void *args) ...@@ -1537,82 +1617,15 @@ void x11_event_thread(void *args)
x11.XBell(dpy, 100); x11.XBell(dpy, 100);
break; break;
case X11_LOCAL_SETICON: { case X11_LOCAL_SETICON: {
#if 0
// This doesn't work on ChromeOS, presumably because XWayland sucks. // This doesn't work on ChromeOS, presumably because XWayland sucks.
Atom wmicon = x11.XInternAtom(dpy, "_NET_WM_ICON", False); Atom wmicon = x11.XInternAtom(dpy, "_NET_WM_ICON", False);
if (wmicon) { 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.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); x11.XFlush(dpy);
} }
set_icon(&lev.data.icon_data[2], lev.data.icon_data[0], NULL);
free(lev.data.icon_data); free(lev.data.icon_data);
break; break;
#else
Pixmap opm = icn;
Pixmap opmm = icn_mask;
XGCValues gcv = {
.function = GXcopy,
.foreground = black | 0xff000000,
.background = white
};
icn = x11.XCreatePixmap(dpy, DefaultRootWindow(dpy), lev.data.icon_data[0], lev.data.icon_data[1], depth);
GC igc = x11.XCreateGC(dpy, icn, GCFunction | GCForeground | GCBackground | GCGraphicsExposures, &gcv);
icn_mask = x11.XCreatePixmap(dpy, DefaultRootWindow(dpy), lev.data.icon_data[0], lev.data.icon_data[1], 1);
GC imgc = x11.XCreateGC(dpy, icn_mask, GCFunction | GCForeground | GCBackground | GCGraphicsExposures, &gcv);
int x,y,i;
bool fail = (!icn) || (!icn_mask);
if (!fail) {
for (x = 0, i = 2; x < lev.data.icon_data[0]; x++) {
for (y = 0; y < lev.data.icon_data[1]; y++) {
XColor fg = {0};
unsigned short tmp;
if (lev.data.icon_data[i] & 0xff000000) {
tmp = (lev.data.icon_data[i] & 0xff0000) >> 16;
fg.red = tmp << 8 | tmp;
tmp = (lev.data.icon_data[i] & 0xff00) >> 8;
fg.green = tmp << 8 | tmp;
tmp = (lev.data.icon_data[i] & 0xff);
fg.blue = tmp << 8 | tmp;
fg.flags = DoRed | DoGreen | DoBlue;
if (x11.XAllocColor(dpy, wincmap, &fg) == 0)
fail = true;
else {
x11.XSetForeground(dpy, igc, fg.pixel);
x11.XDrawPoint(dpy, icn, igc, y, x);
x11.XSetForeground(dpy, imgc, white);
x11.XDrawPoint(dpy, icn_mask, imgc, y, x);
}
if (fail)
break;
}
else {
x11.XSetForeground(dpy, imgc, black);
x11.XDrawPoint(dpy, icn_mask, imgc, y, x);
}
i++;
}
if (fail)
break;
}
}
if (!fail) {
XWMHints *hints = x11.XGetWMHints(dpy, win);
if (!hints)
hints = x11.XAllocWMHints();
if (hints) {
hints->flags |= IconPixmapHint | IconMaskHint;
hints->icon_pixmap = icn;
hints->icon_mask = icn_mask;
x11.XSetWMHints(dpy, win, hints);
x11.XFree(hints);
if (opm)
x11.XFreePixmap(dpy, opm);
if (opmm)
x11.XFreePixmap(dpy, opmm);
}
}
x11.XFreeGC(dpy, igc);
x11.XFreeGC(dpy, imgc);
#endif
} }
case X11_LOCAL_MOUSEPOINTER: { case X11_LOCAL_MOUSEPOINTER: {
unsigned shape = UINT_MAX; unsigned shape = UINT_MAX;
......
...@@ -1558,6 +1558,8 @@ main(int argc, char **argv) ...@@ -1558,6 +1558,8 @@ main(int argc, char **argv)
vparams[cvmode].charheight = settings.custom_fontheight; vparams[cvmode].charheight = settings.custom_fontheight;
vparams[cvmode].aspect_width = settings.custom_aw; vparams[cvmode].aspect_width = settings.custom_aw;
vparams[cvmode].aspect_height = settings.custom_ah; vparams[cvmode].aspect_height = settings.custom_ah;
ciolib_initial_icon = syncterm_icon.pixel_data;
ciolib_initial_icon_width = syncterm_icon.width;
ciolib_initial_scaling = settings.scaling_factor; ciolib_initial_scaling = settings.scaling_factor;
ciolib_mode = settings.output_mode; ciolib_mode = settings.output_mode;
if (settings.startup_mode != SCREEN_MODE_CURRENT) if (settings.startup_mode != SCREEN_MODE_CURRENT)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment