|
On 17 May 2021, at 18:09, Will B wrote:
>
> Following the instructions here https://www.fltk.org/doc-1.3/osissues.html , I tried to set my main window icon with the following code
>
> #include <X11/xpm.h>
> fl_open_display(); // needed if display has not been previously opened
>
> Pixmap pm;
> Pixmap mask;
> XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display), pmSpiritvnc_xpm, &pm, &mask, NULL);
>
> app->mainWin->icon(reinterpret_cast<void *>(pm));
>
> Unfortunately this gives a compile error:
>
> In file included from /usr/include/X11/Xlib.h:47,
> from /usr/include/FL/x.H:37,
> from /usr/include/FL/fl_draw.H:27,
> from src/app.h:43,
> from src/spiritvnc.cxx:47:
> /usr/include/X11/xpm.h: In function ‘int main(int, char**)’:
> /usr/include/X11/xpm.h:286:1: error: expected unqualified-id before string constant
> _XFUNCPROTOBEGIN
> ^~~~~~~~~~~~~~~~
> src/spiritvnc.cxx:94:5: error: ‘XpmCreatePixmapFromData’ was not declared in this scope
> XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display), pmSpiritvnc_xpm, &pm, &mask, NULL);
> ^~~~~~~~~~~~~~~~~~~~~~~
> src/spiritvnc.cxx:94:5: note: suggested alternative: ‘XCreatePixmapFromData’
> XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display), pmSpiritvnc_xpm, &pm, &mask, NULL);
> ^~~~~~~~~~~~~~~~~~~~~~~
> XCreatePixmapFromData
>
> I am using antiX Linux 19.3, which is based on Debian. All the dev packages are installed and as noted on that OS Issues page, I am calling Fl_Window::show(int argc, char** argv). I also tried the XCreatePixmapFromData method, but it produces the same or similar error message. I have grepped for XpmCreatePixmapFromData in /usr/include and it does show up in X11/xpm.h.
>
> I'm not a big Xlib user -- is there something else I should try?
Not sure... This is a “works for me” sort of answer, but here’s some code I use. This is pretty old, so there may be better fltk’ish ways these days, but this (still) works for me.
So, amongst the headers, ifdef’d for X11 builds I have:
# include <X11/xpm.h>
# include "media/fn5x64.xpm”
Then in main(), just before I show the main window I have (also suitably ifdef’d, of course...)
fl_open_display(); // Make sure the display is available before we try and change it!
Pixmap pixmap, mask; // create pixmaps to hold the icon image and its mask
// load the XPM and prepare the mask
XpmCreatePixmapFromData(fl_display, DefaultRootWindow(fl_display), (char**)fn5x64_xpm_data, &pixmap, &mask, 0);
// assign to the fltk main window
// note that the fltk icon handling DOES NOT honour transparency,
// so we fix that AFTER the window is shown (see below)
main_window->icon((char*)pixmap);
/* Show the main window */
main_win->window->show();
Then after the window is mapped I fix up icon transparency issue with:
// The fltk icon code doesn't handle XPM transparency well, work around that here...
{
// read in the current window hints, then modify them to allow icon transparency
XWMHints* hints = XGetWMHints(fl_display, fl_xid(main_window));
hints->flags |= IconMaskHint; // ensure transparency mask is enabled for the XPM icon
hints->icon_mask = mask; // set the transparency mask
XSetWMHints(fl_display, fl_xid(main_window), hints);
XFree(hints);
}
And that’s pretty much it...
I’ve no clue what causes the compiler issue you are seeing.
--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/8764CCDB-E36A-4E8C-848A-673E372F0D73%40gmail.com.
[ Direct Link to Message ] | |