A mirror of phillbush's xmenu.
 
 
 
 
 

108 lines
3.0 KiB

  1. #define PROGNAME "xmenu"
  2. /* Actions for the main loop */
  3. #define ACTION_NOP 0
  4. #define ACTION_MAP 1<<0
  5. #define ACTION_DRAW 1<<1
  6. /* enum for keyboard menu navigation */
  7. enum { ITEMPREV, ITEMNEXT, ITEMFIRST, ITEMLAST };
  8. /* enum for text alignment */
  9. enum {LeftAlignment, CenterAlignment, RightAlignment};
  10. /* macros */
  11. #define LEN(x) (sizeof (x) / sizeof (x[0]))
  12. #define MAX(x,y) ((x)>(y)?(x):(y))
  13. #define MIN(x,y) ((x)<(y)?(x):(y))
  14. #define BETWEEN(x, a, b) ((a) <= (x) && (x) <= (b))
  15. #define GETNUM(n, s) { \
  16. unsigned long __TMP__; \
  17. if ((__TMP__ = strtoul((s), NULL, 10)) < INT_MAX) \
  18. (n) = __TMP__; \
  19. }
  20. /* color enum */
  21. enum {ColorFG, ColorBG, ColorLast};
  22. /* EWMH atoms */
  23. enum {NetWMName, NetWMWindowType, NetWMWindowTypePopupMenu, NetLast};
  24. /* configuration structure */
  25. struct Config {
  26. /* the values below are set by config.h */
  27. const char *font;
  28. const char *background_color;
  29. const char *foreground_color;
  30. const char *selbackground_color;
  31. const char *selforeground_color;
  32. const char *separator_color;
  33. const char *border_color;
  34. int width_pixels;
  35. int height_pixels;
  36. int border_pixels;
  37. int separator_pixels;
  38. int gap_pixels;
  39. int triangle_width;
  40. int triangle_height;
  41. int iconpadding;
  42. int horzpadding;
  43. int alignment;
  44. /* the values below are set by options */
  45. int monitor;
  46. int posx, posy; /* rootmenu position */
  47. /* the value below is computed by xmenu */
  48. int iconsize;
  49. };
  50. /* draw context structure */
  51. struct DC {
  52. XftColor normal[ColorLast];
  53. XftColor selected[ColorLast];
  54. XftColor border;
  55. XftColor separator;
  56. GC gc;
  57. FcPattern *pattern;
  58. XftFont **fonts;
  59. size_t nfonts;
  60. };
  61. /* menu item structure */
  62. struct Item {
  63. char *label; /* string to be drawed on menu */
  64. char *output; /* string to be outputed when item is clicked */
  65. char *file; /* filename of the icon */
  66. int y; /* item y position relative to menu */
  67. int h; /* item height */
  68. int textw; /* text width */
  69. struct Item *prev; /* previous item */
  70. struct Item *next; /* next item */
  71. struct Menu *submenu; /* submenu spawned by clicking on item */
  72. Drawable sel, unsel; /* pixmap for selected and unselected item */
  73. Imlib_Image icon;
  74. };
  75. /* monitor geometry structure */
  76. struct Monitor {
  77. int x, y, w, h; /* monitor geometry */
  78. };
  79. /* menu structure */
  80. struct Menu {
  81. struct Menu *parent; /* parent menu */
  82. struct Item *caller; /* item that spawned the menu */
  83. struct Item *list; /* list of items contained by the menu */
  84. struct Item *selected; /* item currently selected in the menu */
  85. int x, y, w, h; /* menu geometry */
  86. int hasicon; /* whether the menu has item with icons */
  87. int drawn; /* whether the menu was already drawn */
  88. int maxtextw; /* maximum text width */
  89. unsigned level; /* menu level relative to root */
  90. Window win; /* menu window to map on the screen */
  91. XIC xic; /* input context */
  92. };