You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fltk-1_v3.3.0-icons.patch 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. diff -ur fltk-1.3.2.org/FL/Fl_Window.H fltk-1.3.2/FL/Fl_Window.H
  2. --- fltk-1.3.2.org/FL/Fl_Window.H 2013-01-16 10:49:40.904228200 +0100
  3. +++ fltk-1.3.2/FL/Fl_Window.H 2013-01-16 10:49:55.554353925 +0100
  4. @@ -22,6 +22,10 @@
  5. #ifndef Fl_Window_H
  6. #define Fl_Window_H
  7. +#ifdef WIN32
  8. +#include <windows.h>
  9. +#endif
  10. +
  11. #include "Fl_Group.H"
  12. #define FL_WINDOW 0xF0 ///< window type id all subclasses have type() >= this
  13. @@ -73,9 +77,19 @@
  14. friend class Fl_X;
  15. Fl_X *i; // points at the system-specific stuff
  16. + struct icon_data {
  17. + const void *legacy_icon;
  18. + Fl_RGB_Image **icons;
  19. + int count;
  20. +#ifdef WIN32
  21. + HICON big_icon;
  22. + HICON small_icon;
  23. +#endif
  24. + };
  25. +
  26. const char* iconlabel_;
  27. char* xclass_;
  28. - const void* icon_;
  29. + struct icon_data *icon_;
  30. // size_range stuff:
  31. int minw, minh, maxw, maxh;
  32. int dw, dh, aspect;
  33. @@ -121,6 +135,8 @@
  34. */
  35. int force_position() const { return ((flags() & FORCE_POSITION)?1:0); }
  36. + void free_icons();
  37. +
  38. public:
  39. /**
  40. @@ -350,6 +366,18 @@
  41. static const char *default_xclass();
  42. const char* xclass() const;
  43. void xclass(const char* c);
  44. +
  45. + static void default_icon(const Fl_RGB_Image*);
  46. + static void default_icons(const Fl_RGB_Image*[], int);
  47. + void icon(const Fl_RGB_Image*);
  48. + void icons(const Fl_RGB_Image*[], int);
  49. +
  50. +#ifdef WIN32
  51. + static void default_icons(HICON big_icon, HICON small_icon);
  52. + void icons(HICON big_icon, HICON small_icon);
  53. +#endif
  54. +
  55. + /* for legacy compatibility */
  56. const void* icon() const;
  57. void icon(const void * ic);
  58. diff -ur fltk-1.3.2.org/FL/mac.H fltk-1.3.2/FL/mac.H
  59. --- fltk-1.3.2.org/FL/mac.H 2013-01-16 10:49:40.904228200 +0100
  60. +++ fltk-1.3.2/FL/mac.H 2013-01-16 10:49:55.554353925 +0100
  61. @@ -120,6 +120,9 @@
  62. void collapse(void);
  63. WindowRef window_ref(void);
  64. void set_key_window(void);
  65. + // OS X doesn't have per window icons
  66. + static void set_default_icons(const Fl_RGB_Image*[], int) {};
  67. + void set_icons() {};
  68. int set_cursor(Fl_Cursor);
  69. int set_cursor(const Fl_RGB_Image*, int, int);
  70. static CGImageRef CGImage_from_window_rect(Fl_Window *win, int x, int y, int w, int h);
  71. diff -ur fltk-1.3.2.org/FL/win32.H fltk-1.3.2/FL/win32.H
  72. --- fltk-1.3.2.org/FL/win32.H 2013-01-16 10:49:40.904228200 +0100
  73. +++ fltk-1.3.2/FL/win32.H 2013-01-16 10:49:55.555355617 +0100
  74. @@ -84,6 +84,9 @@
  75. void flush() {w->flush();}
  76. void set_minmax(LPMINMAXINFO minmax);
  77. void mapraise();
  78. + static void set_default_icons(const Fl_RGB_Image*[], int);
  79. + static void set_default_icons(HICON, HICON);
  80. + void set_icons();
  81. int set_cursor(Fl_Cursor);
  82. int set_cursor(const Fl_RGB_Image*, int, int);
  83. static Fl_X* make(Fl_Window*);
  84. diff -ur fltk-1.3.2.org/FL/x.H fltk-1.3.2/FL/x.H
  85. --- fltk-1.3.2.org/FL/x.H 2013-01-16 10:49:40.904228200 +0100
  86. +++ fltk-1.3.2/FL/x.H 2013-01-16 10:49:55.555355617 +0100
  87. @@ -154,6 +154,8 @@
  88. static Fl_X* i(const Fl_Window* wi) {return wi->i;}
  89. void setwindow(Fl_Window* wi) {w=wi; wi->i=this;}
  90. void sendxjunk();
  91. + static void set_default_icons(const Fl_RGB_Image*[], int);
  92. + void set_icons();
  93. int set_cursor(Fl_Cursor);
  94. int set_cursor(const Fl_RGB_Image*, int, int);
  95. static void make_xid(Fl_Window*,XVisualInfo* =fl_visual, Colormap=fl_colormap);
  96. diff -ur fltk-1.3.2.org/src/Fl.cxx fltk-1.3.2/src/Fl.cxx
  97. --- fltk-1.3.2.org/src/Fl.cxx 2013-01-16 10:49:40.895228113 +0100
  98. +++ fltk-1.3.2/src/Fl.cxx 2013-01-16 10:49:55.556137979 +0100
  99. @@ -1530,6 +1530,8 @@
  100. if (xclass_) {
  101. free(xclass_);
  102. }
  103. + free_icons();
  104. + delete icon_;
  105. }
  106. // FL_SHOW and FL_HIDE are called whenever the visibility of this widget
  107. diff -ur fltk-1.3.2.org/src/Fl_win32.cxx fltk-1.3.2/src/Fl_win32.cxx
  108. --- fltk-1.3.2.org/src/Fl_win32.cxx 2013-01-16 10:49:40.911227539 +0100
  109. +++ fltk-1.3.2/src/Fl_win32.cxx 2013-01-16 10:49:55.556137979 +0100
  110. @@ -1804,6 +1804,8 @@
  111. );
  112. if (lab) free(lab);
  113. + x->set_icons();
  114. +
  115. if (w->fullscreen_active()) {
  116. /* We need to make sure that the fullscreen is created on the
  117. default monitor, ie the desktop where the shortcut is located
  118. @@ -2034,71 +2036,19 @@
  119. ////////////////////////////////////////////////////////////////
  120. -#ifndef IDC_HAND
  121. -# define IDC_HAND MAKEINTRESOURCE(32649)
  122. -#endif // !IDC_HAND
  123. -
  124. -int Fl_X::set_cursor(Fl_Cursor c) {
  125. - LPSTR n;
  126. - HCURSOR new_cursor;
  127. -
  128. - if (c == FL_CURSOR_NONE)
  129. - new_cursor = NULL;
  130. - else {
  131. - switch (c) {
  132. - case FL_CURSOR_ARROW: n = IDC_ARROW; break;
  133. - case FL_CURSOR_CROSS: n = IDC_CROSS; break;
  134. - case FL_CURSOR_WAIT: n = IDC_WAIT; break;
  135. - case FL_CURSOR_INSERT: n = IDC_IBEAM; break;
  136. - case FL_CURSOR_HAND: n = IDC_HAND; break;
  137. - case FL_CURSOR_HELP: n = IDC_HELP; break;
  138. - case FL_CURSOR_MOVE: n = IDC_SIZEALL; break;
  139. - case FL_CURSOR_N:
  140. - case FL_CURSOR_S:
  141. - // FIXME: Should probably have fallbacks for these instead
  142. - case FL_CURSOR_NS: n = IDC_SIZENS; break;
  143. - case FL_CURSOR_NE:
  144. - case FL_CURSOR_SW:
  145. - // FIXME: Dito.
  146. - case FL_CURSOR_NESW: n = IDC_SIZENESW; break;
  147. - case FL_CURSOR_E:
  148. - case FL_CURSOR_W:
  149. - // FIXME: Dito.
  150. - case FL_CURSOR_WE: n = IDC_SIZEWE; break;
  151. - case FL_CURSOR_SE:
  152. - case FL_CURSOR_NW:
  153. - // FIXME: Dito.
  154. - case FL_CURSOR_NWSE: n = IDC_SIZENWSE; break;
  155. - default:
  156. - return 0;
  157. - }
  158. -
  159. - new_cursor = LoadCursor(NULL, n);
  160. - if (new_cursor == NULL)
  161. - return 0;
  162. - }
  163. -
  164. - if ((cursor != NULL) && custom_cursor)
  165. - DestroyIcon(cursor);
  166. -
  167. - cursor = new_cursor;
  168. - custom_cursor = 0;
  169. -
  170. - SetCursor(cursor);
  171. -
  172. - return 1;
  173. -}
  174. -
  175. -int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
  176. +static HICON image_to_icon(const Fl_RGB_Image *image, bool is_icon=true,
  177. + int hotx = 0, int hoty = 0) {
  178. BITMAPV5HEADER bi;
  179. HBITMAP bitmap, mask;
  180. DWORD *bits;
  181. - HCURSOR new_cursor;
  182. + HICON icon;
  183. + if (!is_icon) {
  184. if ((hotx < 0) || (hotx >= image->w()))
  185. - return 0;
  186. + return NULL;
  187. if ((hoty < 0) || (hoty >= image->h()))
  188. - return 0;
  189. + return NULL;
  190. + }
  191. memset(&bi, 0, sizeof(BITMAPV5HEADER));
  192. @@ -2120,7 +2070,7 @@
  193. ReleaseDC(NULL, hdc);
  194. if (bits == NULL)
  195. - return 0;
  196. + return NULL;
  197. const uchar *i = (const uchar*)*image->data();
  198. for (int y = 0;y < image->h();y++) {
  199. @@ -2149,22 +2099,206 @@
  200. mask = CreateBitmap(image->w(),image->h(),1,1,NULL);
  201. if (mask == NULL) {
  202. DeleteObject(bitmap);
  203. - return 0;
  204. + return NULL;
  205. }
  206. ICONINFO ii;
  207. - ii.fIcon = FALSE;
  208. + ii.fIcon = is_icon;
  209. ii.xHotspot = hotx;
  210. ii.yHotspot = hoty;
  211. ii.hbmMask = mask;
  212. ii.hbmColor = bitmap;
  213. - new_cursor = CreateIconIndirect(&ii);
  214. + icon = CreateIconIndirect(&ii);
  215. DeleteObject(bitmap);
  216. DeleteObject(mask);
  217. + if (icon == NULL)
  218. + return NULL;
  219. +
  220. + return icon;
  221. +}
  222. +
  223. +////////////////////////////////////////////////////////////////
  224. +
  225. +static HICON default_big_icon = NULL;
  226. +static HICON default_small_icon = NULL;
  227. +
  228. +const Fl_RGB_Image *find_best_icon(int ideal_width,
  229. + const Fl_RGB_Image *icons[], int count) {
  230. + const Fl_RGB_Image *best;
  231. +
  232. + best = NULL;
  233. +
  234. + for (int i = 0;i < count;i++) {
  235. + if (best == NULL)
  236. + best = icons[i];
  237. + else {
  238. + if (best->w() < ideal_width) {
  239. + if (icons[i]->w() > best->w())
  240. + best = icons[i];
  241. + } else {
  242. + if ((icons[i]->w() >= ideal_width) &&
  243. + (icons[i]->w() < best->w()))
  244. + best = icons[i];
  245. + }
  246. + }
  247. + }
  248. +
  249. + return best;
  250. +}
  251. +
  252. +void Fl_X::set_default_icons(const Fl_RGB_Image *icons[], int count) {
  253. + const Fl_RGB_Image *best_big, *best_small;
  254. +
  255. + if (default_big_icon != NULL)
  256. + DestroyIcon(default_big_icon);
  257. + if (default_small_icon != NULL)
  258. + DestroyIcon(default_small_icon);
  259. +
  260. + best_big = find_best_icon(GetSystemMetrics(SM_CXICON), icons, count);
  261. + best_small = find_best_icon(GetSystemMetrics(SM_CXSMICON), icons, count);
  262. +
  263. + if (best_big != NULL)
  264. + default_big_icon = image_to_icon(best_big);
  265. + else
  266. + default_big_icon = NULL;
  267. +
  268. + if (best_small != NULL)
  269. + default_small_icon = image_to_icon(best_small);
  270. + else
  271. + default_small_icon = NULL;
  272. +}
  273. +
  274. +void Fl_X::set_default_icons(HICON big_icon, HICON small_icon) {
  275. + if (default_big_icon != NULL)
  276. + DestroyIcon(default_big_icon);
  277. + if (default_small_icon != NULL)
  278. + DestroyIcon(default_small_icon);
  279. +
  280. + if (big_icon != NULL)
  281. + default_big_icon = CopyIcon(big_icon);
  282. + if (small_icon != NULL)
  283. + default_small_icon = CopyIcon(small_icon);
  284. +}
  285. +
  286. +void Fl_X::set_icons() {
  287. + HICON big_icon, small_icon;
  288. +
  289. + big_icon = NULL;
  290. + small_icon = NULL;
  291. +
  292. + if (w->icon_->count) {
  293. + const Fl_RGB_Image *best_big, *best_small;
  294. +
  295. + best_big = find_best_icon(GetSystemMetrics(SM_CXICON),
  296. + (const Fl_RGB_Image **)w->icon_->icons,
  297. + w->icon_->count);
  298. + best_small = find_best_icon(GetSystemMetrics(SM_CXSMICON),
  299. + (const Fl_RGB_Image **)w->icon_->icons,
  300. + w->icon_->count);
  301. +
  302. + if (best_big != NULL)
  303. + big_icon = image_to_icon(best_big);
  304. + if (best_small != NULL)
  305. + small_icon = image_to_icon(best_small);
  306. + } else {
  307. + big_icon = default_big_icon;
  308. + small_icon = default_small_icon;
  309. + }
  310. +
  311. + if (big_icon != NULL)
  312. + SendMessage(xid, WM_SETICON, ICON_BIG, (LPARAM)big_icon);
  313. + if (small_icon != NULL)
  314. + SendMessage(xid, WM_SETICON, ICON_SMALL, (LPARAM)small_icon);
  315. +
  316. + if (w->icon_->count) {
  317. + if (big_icon != NULL)
  318. + DestroyIcon(big_icon);
  319. + if (small_icon != NULL)
  320. + DestroyIcon(small_icon);
  321. + }
  322. +}
  323. +
  324. +void Fl_Window::default_icons(HICON big_icon, HICON small_icon) {
  325. + Fl_X::set_default_icons(big_icon, small_icon);
  326. +}
  327. +
  328. +void Fl_Window::icons(HICON big_icon, HICON small_icon) {
  329. + free_icons();
  330. +
  331. + if (big_icon != NULL)
  332. + icon_->big_icon = CopyIcon(big_icon);
  333. + if (small_icon != NULL)
  334. + icon_->small_icon = CopyIcon(small_icon);
  335. +
  336. + if (i)
  337. + i->set_icons();
  338. +}
  339. +
  340. +////////////////////////////////////////////////////////////////
  341. +
  342. +#ifndef IDC_HAND
  343. +# define IDC_HAND MAKEINTRESOURCE(32649)
  344. +#endif // !IDC_HAND
  345. +
  346. +int Fl_X::set_cursor(Fl_Cursor c) {
  347. + LPSTR n;
  348. + HCURSOR new_cursor;
  349. +
  350. + if (c == FL_CURSOR_NONE)
  351. + new_cursor = NULL;
  352. + else {
  353. + switch (c) {
  354. + case FL_CURSOR_ARROW: n = IDC_ARROW; break;
  355. + case FL_CURSOR_CROSS: n = IDC_CROSS; break;
  356. + case FL_CURSOR_WAIT: n = IDC_WAIT; break;
  357. + case FL_CURSOR_INSERT: n = IDC_IBEAM; break;
  358. + case FL_CURSOR_HAND: n = IDC_HAND; break;
  359. + case FL_CURSOR_HELP: n = IDC_HELP; break;
  360. + case FL_CURSOR_MOVE: n = IDC_SIZEALL; break;
  361. + case FL_CURSOR_N:
  362. + case FL_CURSOR_S:
  363. + // FIXME: Should probably have fallbacks for these instead
  364. + case FL_CURSOR_NS: n = IDC_SIZENS; break;
  365. + case FL_CURSOR_NE:
  366. + case FL_CURSOR_SW:
  367. + // FIXME: Dito.
  368. + case FL_CURSOR_NESW: n = IDC_SIZENESW; break;
  369. + case FL_CURSOR_E:
  370. + case FL_CURSOR_W:
  371. + // FIXME: Dito.
  372. + case FL_CURSOR_WE: n = IDC_SIZEWE; break;
  373. + case FL_CURSOR_SE:
  374. + case FL_CURSOR_NW:
  375. + // FIXME: Dito.
  376. + case FL_CURSOR_NWSE: n = IDC_SIZENWSE; break;
  377. + default:
  378. + return 0;
  379. + }
  380. +
  381. + new_cursor = LoadCursor(NULL, n);
  382. + if (new_cursor == NULL)
  383. + return 0;
  384. + }
  385. +
  386. + if ((cursor != NULL) && custom_cursor)
  387. + DestroyIcon(cursor);
  388. +
  389. + cursor = new_cursor;
  390. + custom_cursor = 0;
  391. +
  392. + SetCursor(cursor);
  393. +
  394. + return 1;
  395. +}
  396. +
  397. +int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) {
  398. + HCURSOR new_cursor;
  399. +
  400. + new_cursor = image_to_icon(image, false, hotx, hoty);
  401. if (new_cursor == NULL)
  402. return 0;
  403. diff -ur fltk-1.3.2.org/src/Fl_Window.cxx fltk-1.3.2/src/Fl_Window.cxx
  404. --- fltk-1.3.2.org/src/Fl_Window.cxx 2013-01-16 10:49:40.908130903 +0100
  405. +++ fltk-1.3.2/src/Fl_Window.cxx 2013-01-16 10:49:55.557353865 +0100
  406. @@ -23,6 +23,7 @@
  407. #include <config.h>
  408. #include <FL/Fl.H>
  409. #include <FL/x.H>
  410. +#include <FL/Fl_RGB_Image.H>
  411. #include <FL/Fl_Window.H>
  412. #include <stdlib.h>
  413. #include "flstring.h"
  414. @@ -45,7 +46,8 @@
  415. }
  416. i = 0;
  417. xclass_ = 0;
  418. - icon_ = 0;
  419. + icon_ = new icon_data;
  420. + memset(icon_, 0, sizeof(*icon_));
  421. iconlabel_ = 0;
  422. resizable(0);
  423. size_range_set = 0;
  424. @@ -264,16 +266,68 @@
  425. }
  426. }
  427. +void Fl_Window::default_icon(const Fl_RGB_Image *icon) {
  428. + default_icons(&icon, 1);
  429. +}
  430. +
  431. +void Fl_Window::default_icons(const Fl_RGB_Image **icons, int count) {
  432. + Fl_X::set_default_icons(icons, count);
  433. +}
  434. +
  435. +void Fl_Window::icon(const Fl_RGB_Image *icon) {
  436. + icons(&icon, 1);
  437. +}
  438. +
  439. +void Fl_Window::icons(const Fl_RGB_Image **icons, int count) {
  440. + free_icons();
  441. +
  442. + if (count > 0) {
  443. + icon_->icons = new Fl_RGB_Image*[count];
  444. + icon_->count = count;
  445. + // FIXME: Fl_RGB_Image lacks const modifiers on methods
  446. + for (int i = 0;i < count;i++)
  447. + icon_->icons[i] = (Fl_RGB_Image*)((Fl_RGB_Image*)icons[i])->copy();
  448. + }
  449. +
  450. + if (i)
  451. + i->set_icons();
  452. +}
  453. +
  454. /** Gets the current icon window target dependent data. */
  455. const void *Fl_Window::icon() const {
  456. - return icon_;
  457. + return icon_->legacy_icon;
  458. }
  459. /** Sets the current icon window target dependent data. */
  460. void Fl_Window::icon(const void * ic) {
  461. - icon_ = ic;
  462. + free_icons();
  463. + icon_->legacy_icon = ic;
  464. }
  465. +void Fl_Window::free_icons() {
  466. + int i;
  467. +
  468. + icon_->legacy_icon = 0L;
  469. +
  470. + if (icon_->icons) {
  471. + for (i = 0;i < icon_->count;i++)
  472. + delete icon_->icons[i];
  473. + delete [] icon_->icons;
  474. + icon_->icons = 0L;
  475. + }
  476. +
  477. + icon_->count = 0;
  478. +
  479. +#ifdef WIN32
  480. + if (icon_->big_icon)
  481. + DestroyIcon(icon_->big_icon);
  482. + if (icon_->small_icon)
  483. + DestroyIcon(icon_->small_icon);
  484. +
  485. + icon_->big_icon = NULL;
  486. + icon_->small_icon = NULL;
  487. +#endif
  488. +}
  489. //
  490. // End of "$Id: Fl_Window.cxx 9706 2012-11-06 20:46:14Z matt $".
  491. diff -ur fltk-1.3.2.org/src/Fl_x.cxx fltk-1.3.2/src/Fl_x.cxx
  492. --- fltk-1.3.2.org/src/Fl_x.cxx 2013-01-16 10:49:40.912227213 +0100
  493. +++ fltk-1.3.2/src/Fl_x.cxx 2013-01-16 10:49:55.558137113 +0100
  494. @@ -345,6 +345,7 @@
  495. Atom fl_NET_WM_STATE;
  496. Atom fl_NET_WM_STATE_FULLSCREEN;
  497. Atom fl_NET_WORKAREA;
  498. +Atom fl_NET_WM_ICON;
  499. /*
  500. X defines 32-bit-entities to have a format value of max. 32,
  501. @@ -709,6 +710,7 @@
  502. fl_NET_WM_STATE = XInternAtom(d, "_NET_WM_STATE", 0);
  503. fl_NET_WM_STATE_FULLSCREEN = XInternAtom(d, "_NET_WM_STATE_FULLSCREEN", 0);
  504. fl_NET_WORKAREA = XInternAtom(d, "_NET_WORKAREA", 0);
  505. + fl_NET_WM_ICON = XInternAtom(d, "_NET_WM_ICON", 0);
  506. if (sizeof(Atom) < 4)
  507. atom_bits = sizeof(Atom) * 8;
  508. @@ -2138,12 +2140,14 @@
  509. fl_show_iconic = 0;
  510. showit = 0;
  511. }
  512. - if (win->icon()) {
  513. - hints->icon_pixmap = (Pixmap)win->icon();
  514. + if (win->icon_->legacy_icon) {
  515. + hints->icon_pixmap = (Pixmap)win->icon_->legacy_icon;
  516. hints->flags |= IconPixmapHint;
  517. }
  518. XSetWMHints(fl_display, xp->xid, hints);
  519. XFree(hints);
  520. +
  521. + xp->set_icons();
  522. }
  523. // set the window type for menu and tooltip windows to avoid animations (compiz)
  524. @@ -2263,6 +2267,93 @@
  525. ////////////////////////////////////////////////////////////////
  526. +static unsigned long *default_net_wm_icons = 0L;
  527. +static size_t default_net_wm_icons_size = 0;
  528. +
  529. +void icons_to_property(const Fl_RGB_Image *icons[], int count,
  530. + unsigned long **property, size_t *len) {
  531. + size_t sz;
  532. + unsigned long *data;
  533. +
  534. + sz = 0;
  535. + for (int i = 0;i < count;i++)
  536. + sz += 2 + icons[i]->w() * icons[i]->h();
  537. +
  538. + // FIXME: Might want to sort the icons
  539. +
  540. + *property = data = new unsigned long[sz];
  541. + *len = sz;
  542. +
  543. + for (int i = 0;i < count;i++) {
  544. + const Fl_RGB_Image *image;
  545. +
  546. + image = icons[i];
  547. +
  548. + data[0] = image->w();
  549. + data[1] = image->h();
  550. + data += 2;
  551. +
  552. + const uchar *in = (const uchar*)*image->data();
  553. + for (int y = 0;y < image->h();y++) {
  554. + for (int x = 0;x < image->w();x++) {
  555. + switch (image->d()) {
  556. + case 1:
  557. + *data = ( 0xff<<24) | (in[0]<<16) | (in[0]<<8) | in[0];
  558. + break;
  559. + case 2:
  560. + *data = (in[1]<<24) | (in[0]<<16) | (in[0]<<8) | in[0];
  561. + break;
  562. + case 3:
  563. + *data = ( 0xff<<24) | (in[0]<<16) | (in[1]<<8) | in[2];
  564. + break;
  565. + case 4:
  566. + *data = (in[3]<<24) | (in[0]<<16) | (in[1]<<8) | in[2];
  567. + break;
  568. + }
  569. + in += image->d();
  570. + data++;
  571. + }
  572. + in += image->ld();
  573. + }
  574. + }
  575. +}
  576. +
  577. +void Fl_X::set_default_icons(const Fl_RGB_Image *icons[], int count) {
  578. + if (default_net_wm_icons) {
  579. + delete [] default_net_wm_icons;
  580. + default_net_wm_icons = 0L;
  581. + default_net_wm_icons_size = 0;
  582. + }
  583. +
  584. + if (count > 0)
  585. + icons_to_property(icons, count,
  586. + &default_net_wm_icons, &default_net_wm_icons_size);
  587. +}
  588. +
  589. +void Fl_X::set_icons() {
  590. + unsigned long *net_wm_icons;
  591. + size_t net_wm_icons_size;
  592. +
  593. + if (w->icon_->count) {
  594. + icons_to_property((const Fl_RGB_Image **)w->icon_->icons, w->icon_->count,
  595. + &net_wm_icons, &net_wm_icons_size);
  596. + } else {
  597. + net_wm_icons = default_net_wm_icons;
  598. + net_wm_icons_size = default_net_wm_icons_size;
  599. + }
  600. +
  601. + XChangeProperty (fl_display, xid, fl_NET_WM_ICON, XA_CARDINAL, 32,
  602. + PropModeReplace, (unsigned char*) net_wm_icons, net_wm_icons_size);
  603. +
  604. + if (w->icon_->count) {
  605. + delete [] net_wm_icons;
  606. + net_wm_icons = 0L;
  607. + net_wm_icons_size = 0;
  608. + }
  609. +}
  610. +
  611. +////////////////////////////////////////////////////////////////
  612. +
  613. int Fl_X::set_cursor(Fl_Cursor c) {
  614. unsigned int shape;
  615. Cursor xc;