My build of dwm
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

102 lines
2.6 KiB

  1. From 6b5e23cdf8108a9033acc7c21c8926c0c72647fc Mon Sep 17 00:00:00 2001
  2. From: Adham Zahran <adhamzahranfms@gmail.com>
  3. Date: Wed, 27 May 2020 18:07:57 +0200
  4. Subject: [PATCH] Top bar now has buttons that launches programs
  5. ---
  6. config.def.h | 8 ++++++++
  7. dwm.c | 36 ++++++++++++++++++++++++++++++++++--
  8. 2 files changed, 42 insertions(+), 2 deletions(-)
  9. diff --git a/config.def.h b/config.def.h
  10. index 1c0b587..9231cd5 100644
  11. --- a/config.def.h
  12. +++ b/config.def.h
  13. @@ -21,6 +21,14 @@ static const char *colors[][3] = {
  14. /* tagging */
  15. static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  16. +/* launcher commands (They must be NULL terminated) */
  17. +static const char* surf[] = { "surf", "duckduckgo.com", NULL };
  18. +
  19. +static const Launcher launchers[] = {
  20. + /* command name to display */
  21. + { surf, "surf" },
  22. +};
  23. +
  24. static const Rule rules[] = {
  25. /* xprop(1):
  26. * WM_CLASS(STRING) = instance, class
  27. diff --git a/dwm.c b/dwm.c
  28. index 9fd0286..79e7e20 100644
  29. --- a/dwm.c
  30. +++ b/dwm.c
  31. @@ -141,6 +141,11 @@ typedef struct {
  32. int monitor;
  33. } Rule;
  34. +typedef struct {
  35. + const char** command;
  36. + const char* name;
  37. +} Launcher;
  38. +
  39. /* function declarations */
  40. static void applyrules(Client *c);
  41. static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
  42. @@ -438,9 +443,26 @@ buttonpress(XEvent *e)
  43. if (i < LENGTH(tags)) {
  44. click = ClkTagBar;
  45. arg.ui = 1 << i;
  46. - } else if (ev->x < x + blw)
  47. + goto execute_handler;
  48. + } else if (ev->x < x + blw) {
  49. click = ClkLtSymbol;
  50. - else if (ev->x > selmon->ww - TEXTW(stext))
  51. + goto execute_handler;
  52. + }
  53. +
  54. + x += blw;
  55. +
  56. + for(i = 0; i < LENGTH(launchers); i++) {
  57. + x += TEXTW(launchers[i].name);
  58. +
  59. + if (ev->x < x) {
  60. + Arg a;
  61. + a.v = launchers[i].command;
  62. + spawn(&a);
  63. + return;
  64. + }
  65. + }
  66. +
  67. + if (ev->x > selmon->ww - TEXTW(stext))
  68. click = ClkStatusText;
  69. else
  70. click = ClkWinTitle;
  71. @@ -450,6 +472,9 @@ buttonpress(XEvent *e)
  72. XAllowEvents(dpy, ReplayPointer, CurrentTime);
  73. click = ClkClientWin;
  74. }
  75. +
  76. +execute_handler:
  77. +
  78. for (i = 0; i < LENGTH(buttons); i++)
  79. if (click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
  80. && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
  81. @@ -728,6 +753,13 @@ drawbar(Monitor *m)
  82. w = blw = TEXTW(m->ltsymbol);
  83. drw_setscheme(drw, scheme[SchemeNorm]);
  84. x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0);
  85. +
  86. + for (i = 0; i < LENGTH(launchers); i++)
  87. + {
  88. + w = TEXTW(launchers[i].name);
  89. + drw_text(drw, x, 0, w, bh, lrpad / 2, launchers[i].name, urg & 1 << i);
  90. + x += w;
  91. + }
  92. if ((w = m->ww - tw - x) > bh) {
  93. if (m->sel) {
  94. --
  95. 2.17.1