我的目的是画一个图标到标题栏的一个基本的wm我正在试图创建。
我已经通过谷歌搜索,尝试了不同的解决方案,但到目前为止,还没有一个可行的解决方案(可能只是因为我缺乏知识),我设法从一个图标上显示了一些东西,但它甚至不接近图标是什么:
图标是一张软盘(有颜色)
所以我用来显示它的代码如下:
void get_system_icon(char* icon_name, Display *display, Window win){
printf("Placeholder");
unsigned int img_h;
unsigned int img_w;
unsigned int hotspot_x;
unsigned int hotspot_y;
Pixmap icon;
XTextProperty icon_name_property;
int width, height;
int h_x, h_y;
char *filename = "../default.ico";
Imlib_Image img;
img = imlib_load_image(filename);
if(img == NULL){
printf("Error loading imlibimage");
}
ScreenInfos infos = get_screen_informations(display);
Screen *screen = DefaultScreenOfDisplay(display);
imlib_context_set_image(img);
img_w = imlib_image_get_width();
img_h = imlib_image_get_height();
printf("Img size: %d - %d\n", img_w, img_h);
imlib_blend_image_onto_image(img,0,0,0, img_w, img_h, 0,0, infos.width,infos.height);
Pixmap my_pix;
my_pix = XCreatePixmap(display, win, img_w, img_h, DefaultDepthOfScreen(screen));
imlib_context_set_display(display);
imlib_context_set_visual(DefaultVisualOfScreen(screen));
imlib_context_set_colormap(DefaultColormapOfScreen(screen));
imlib_context_set_drawable(my_pix);
imlib_render_image_on_drawable(0, 0);
XSizeHints* win_size_hints;
XWMHints* win_hints;
int return_code;
return_code = XStringListToTextProperty(&icon_name,
1,
&icon_name_property);
if(return_code == 0) {
printf("Error");
}
XSetWMIconName(display, win, &icon_name_property);
win_hints = XAllocWMHints();
if (!win_size_hints) {
fprintf(stderr, "XAllocSizeHints - out of memory\n");
exit(1);
}
win_hints->flags = IconPixmapHint | StateHint | IconPositionHint;
win_hints->icon_pixmap = my_pix;
win_hints->initial_state = IconicState;
win_hints->icon_x = 0;
win_hints->icon_y = 0;
/* pass the hints to the window manager. */
XSetWMHints(display, win, win_hints);
/* finally, we can free the WM hints structure. */
GC gc;
gc = XCreateGC(display, win, 0, NULL);
//XPutImage(display, win, gc,
XSetBackground(display, gc, WhitePixel(display, DefaultScreen(display)));
//WhitePixel(display, DefaultScreen(display));
XCopyPlane(display, my_pix, win, gc,
0, 0,
30, 30,
0, 0,
1);
XFree(win_hints);
XFlush(display);
}
有几个问题我在任何地方都找不到答案,
-
在我搜索的许多解决方案中,我注意到图标数据存储在WM_提示中,但不清楚该结构是否只是保存图标信息以备将来参考,或者以某种方式实际显示图标(我认为第一种情况适用的更多,在这些例子中,我发现显示一个图标,我想是因为当前的窗口管理器正在添加它)。
-
我使用了一个类似的代码来设置wm的背景,在这种情况下它是有效的(检查这里:
https://github.com/inuyasha82/uwm/blob/master/src/background.c
)所以我想我应该做些类似的事情,但显然不是,怎么了?
-
我尝试使用bmp和ico格式,我注意到输出是不同的(但总是2种颜色,完全错误)
所以我很确定我的代码是错的,但是我找不到一个很好的例子来说明如何在窗口上绘制图标,有人能帮我吗?