FLTK 1.3.4 - Setting Window icon in Linux

70 views
Skip to first unread message

Will B

unread,
May 17, 2021, 1:09:03 PM5/17/21
to fltk.general
Greetings!

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?

PS: Google groups is very clunky for code entry and other programming-related text-editing...have you thought about using something else?

Thank you! :-)

Will Brokenbourgh

Ian MacArthur

unread,
May 17, 2021, 4:38:45 PM5/17/21
to fltkg...@googlegroups.com
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.

Will B

unread,
May 17, 2021, 4:42:37 PM5/17/21
to fltk.general
On Monday, May 17, 2021 at 1:38:45 PM UTC-7 Ian MacArthur wrote:
Not sure... This is a “works for me” sort of answer, but here’s some code [snip]


And that’s pretty much it...

I’ve no clue what causes the compiler issue you are seeing.

Hi Ian,

Thanks for the reply. :-)

That looks very usable, if I could get XpmCreatePixmapFromData to actually work at all.  I almost suspect it's either a Debian or antiX issue, but will need to spin some virtual machines up to see.

Thank you!

Will Brokenbourgh

Ian MacArthur

unread,
May 17, 2021, 4:46:48 PM5/17/21
to fltkg...@googlegroups.com
I tested on Ubuntu (which is also debian) so I guess it’s not that.
My best guess would be some headers weirdness, though I do not know what.

At the top of the file I posted those snippets form, I have... (edited to remove the WIN32 and OSX portions)

// FLTK headers
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Sys_Menu_Bar.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Progress.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Native_File_Chooser.H>
#include <FL/Fl_Preferences.H>
#include <FL/x.H>

<snip>

# include <X11/xpm.h>
# include "media/fn5x64.xpm"


And after that XpmCreatePixmapFromData() seems to be happily visible...






Will B

unread,
May 17, 2021, 6:40:01 PM5/17/21
to fltk.general
On Monday, May 17, 2021 at 1:46:48 PM UTC-7 Ian MacArthur wrote:
I tested on Ubuntu (which is also debian) so I guess it’s not that.
My best guess would be some headers weirdness, though I do not know what.

At the top of the file I posted those snippets form, I have... (edited to remove the WIN32 and OSX portions)

// FLTK headers
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Scroll.H>
#include <FL/Fl_Sys_Menu_Bar.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Progress.H>
#include <FL/Fl_Group.H>
#include <FL/Fl_Native_File_Chooser.H>
#include <FL/Fl_Preferences.H>
#include <FL/x.H>

<snip>

# include <X11/xpm.h>
# include "media/fn5x64.xpm"


And after that XpmCreatePixmapFromData() seems to be happily visible...

Hi again Ian,

Just letting everyone know -- I resolved this issue by moving the #include <X11/xpm.h> to above the various FL includes, then it compile fine.  Ugh, the joys of preprocessing directives! :-P

Thanks so much for your time and help Ian! :-)

Will Brokenbourgh

 
Reply all
Reply to author
Forward
0 new messages