A mirror of phillbush's xmenu.
 
 
 
 
 

109 行
3.1 KiB

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