Skip to content

Commit 5d4d3f8

Browse files
committedJul 5, 2016
Finally set a window icon on X11
Since the creation of minetest, it had no window icon on X11. Now we have one. The misc/minetest-xorg-icon-128.png file is a rendering of the misc/minetest.svg file with inkscape, created with something like: inkscape -z -e misc/minetest-xorg-icon-128.png -w 128 -h 128 misc/minetest.svg
1 parent c1bdb55 commit 5d4d3f8

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed
 

‎misc/minetest-xorg-icon-128.png

11 KB
Loading

‎src/client/clientlauncher.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ bool ClientLauncher::run(GameParams &game_params, const Settings &cmd_args)
114114

115115
porting::setXorgClassHint(video_driver->getExposedVideoData(), PROJECT_NAME_C);
116116

117+
porting::setXorgWindowIcon(device,
118+
porting::path_share + "/misc/minetest-xorg-icon-128.png");
119+
117120
/*
118121
This changes the minimum allowed number of vertices in a VBO.
119122
Default is 500.

‎src/porting.cpp

+87
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,93 @@ void setXorgClassHint(const video::SExposedVideoData &video_data,
611611
#endif
612612
}
613613

614+
bool setXorgWindowIcon(IrrlichtDevice *device,
615+
const std::string &icon_file)
616+
{
617+
#ifdef XORG_USED
618+
619+
video::IVideoDriver *v_driver = device->getVideoDriver();
620+
621+
video::IImageLoader *image_loader = NULL;
622+
for (u32 i = v_driver->getImageLoaderCount() - 1; i >= 0; i--) {
623+
if (v_driver->getImageLoader(i)->isALoadableFileExtension(icon_file.c_str())) {
624+
image_loader = v_driver->getImageLoader(i);
625+
break;
626+
}
627+
}
628+
629+
if (!image_loader) {
630+
warningstream << "Could not find image loader for file '"
631+
<< icon_file << "'" << std::endl;
632+
return false;
633+
}
634+
635+
io::IReadFile *icon_f = device->getFileSystem()->createAndOpenFile(icon_file.c_str());
636+
637+
if (!icon_f) {
638+
warningstream << "Could not load icon file '"
639+
<< icon_file << "'" << std::endl;
640+
return false;
641+
}
642+
643+
video::IImage *img = image_loader->loadImage(icon_f);
644+
645+
if (!img) {
646+
warningstream << "Could not load icon file '"
647+
<< icon_file << "'" << std::endl;
648+
icon_f->drop();
649+
return false;
650+
}
651+
652+
u32 height = img->getDimension().Height;
653+
u32 width = img->getDimension().Width;
654+
655+
size_t icon_buffer_len = 2 + height * width;
656+
long *icon_buffer = new long[icon_buffer_len];
657+
658+
icon_buffer[0] = width;
659+
icon_buffer[1] = height;
660+
661+
for (u32 x = 0; x < width; x++) {
662+
for (u32 y = 0; y < height; y++) {
663+
video::SColor col = img->getPixel(x, y);
664+
long pixel_val = 0;
665+
pixel_val |= (u8)col.getAlpha() << 24;
666+
pixel_val |= (u8)col.getRed() << 16;
667+
pixel_val |= (u8)col.getGreen() << 8;
668+
pixel_val |= (u8)col.getBlue();
669+
icon_buffer[2 + x + y * width] = pixel_val;
670+
}
671+
}
672+
673+
img->drop();
674+
icon_f->drop();
675+
676+
const video::SExposedVideoData &video_data = v_driver->getExposedVideoData();
677+
678+
Display *x11_dpl = (Display *)video_data.OpenGLLinux.X11Display;
679+
680+
if (x11_dpl == NULL) {
681+
warningstream << "Could not find x11 display for setting its icon."
682+
<< std::endl;
683+
delete [] icon_buffer;
684+
return false;
685+
}
686+
687+
Window x11_win = (Window)video_data.OpenGLLinux.X11Window;
688+
689+
Atom net_wm_icon = XInternAtom(x11_dpl, "_NET_WM_ICON", False);
690+
Atom cardinal = XInternAtom(x11_dpl, "CARDINAL", False);
691+
XChangeProperty(x11_dpl, x11_win,
692+
net_wm_icon, cardinal, 32,
693+
PropModeReplace, (const unsigned char *)icon_buffer,
694+
icon_buffer_len);
695+
696+
delete [] icon_buffer;
697+
698+
return true;
699+
#endif
700+
}
614701

615702
////
616703
//// Video/Display Information (Client-only)

‎src/porting.h

+3
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ inline const char *getPlatformName()
367367
void setXorgClassHint(const video::SExposedVideoData &video_data,
368368
const std::string &name);
369369

370+
bool setXorgWindowIcon(IrrlichtDevice *device,
371+
const std::string &icon_file);
372+
370373
// This only needs to be called at the start of execution, since all future
371374
// threads in the process inherit this exception handler
372375
void setWin32ExceptionHandler();

1 commit comments

Comments
 (1)

est31 commented on Jul 16, 2016

@est31
ContributorAuthor

No, i think its a bug I've missed with this commit. See #4323

Please sign in to comment.