Another copy of my dotfiles. Because I don't completely trust GitHub.
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.

93 lines
2.8 KiB

4 years ago
  1. From a09e766a4342f580582082a92b2de65f33208eb4 Mon Sep 17 00:00:00 2001
  2. From: Christopher Drelich <cd@cdrakka.com>
  3. Date: Thu, 24 May 2018 00:56:56 -0400
  4. Subject: [PATCH] Function to cycle through available layouts.
  5. MOD-CTRL-, and MOD-CTRL-.
  6. cycle backwards and forwards through available layouts.
  7. Probably only useful if you have a lot of additional layouts.
  8. The NULL, NULL layout should always be the last layout in your list,
  9. in order to guarantee consistent behavior.
  10. ---
  11. config.def.h | 3 +++
  12. dwm.1 | 6 ++++++
  13. dwm.c | 18 ++++++++++++++++++
  14. 3 files changed, 27 insertions(+)
  15. diff --git a/config.def.h b/config.def.h
  16. index a9ac303..153b880 100644
  17. --- a/config.def.h
  18. +++ b/config.def.h
  19. @@ -41,6 +41,7 @@ static const Layout layouts[] = {
  20. { "[]=", tile }, /* first entry is default */
  21. { "><>", NULL }, /* no layout function means floating behavior */
  22. { "[M]", monocle },
  23. + { NULL, NULL },
  24. };
  25. /* key definitions */
  26. @@ -76,6 +77,8 @@ static Key keys[] = {
  27. { MODKEY, XK_t, setlayout, {.v = &layouts[0]} },
  28. { MODKEY, XK_f, setlayout, {.v = &layouts[1]} },
  29. { MODKEY, XK_m, setlayout, {.v = &layouts[2]} },
  30. + { MODKEY|ControlMask, XK_comma, cyclelayout, {.i = -1 } },
  31. + { MODKEY|ControlMask, XK_period, cyclelayout, {.i = +1 } },
  32. { MODKEY, XK_space, setlayout, {0} },
  33. { MODKEY|ShiftMask, XK_space, togglefloating, {0} },
  34. { MODKEY, XK_0, view, {.ui = ~0 } },
  35. diff --git a/dwm.1 b/dwm.1
  36. index 13b3729..165891b 100644
  37. --- a/dwm.1
  38. +++ b/dwm.1
  39. @@ -92,6 +92,12 @@ Sets monocle layout.
  40. .B Mod1\-space
  41. Toggles between current and previous layout.
  42. .TP
  43. +.B Mod1\-Control\-,
  44. +Cycles backwards in layout list.
  45. +.TP
  46. +.B Mod1\-Control\-.
  47. +Cycles forwards in layout list.
  48. +.TP
  49. .B Mod1\-j
  50. Focus next window.
  51. .TP
  52. diff --git a/dwm.c b/dwm.c
  53. index bb95e26..db73000 100644
  54. --- a/dwm.c
  55. +++ b/dwm.c
  56. @@ -157,6 +157,7 @@ static void configure(Client *c);
  57. static void configurenotify(XEvent *e);
  58. static void configurerequest(XEvent *e);
  59. static Monitor *createmon(void);
  60. +static void cyclelayout(const Arg *arg);
  61. static void destroynotify(XEvent *e);
  62. static void detach(Client *c);
  63. static void detachstack(Client *c);
  64. @@ -645,6 +646,23 @@ createmon(void)
  65. }
  66. void
  67. +cyclelayout(const Arg *arg) {
  68. + Layout *l;
  69. + for(l = (Layout *)layouts; l != selmon->lt[selmon->sellt]; l++);
  70. + if(arg->i > 0) {
  71. + if(l->symbol && (l + 1)->symbol)
  72. + setlayout(&((Arg) { .v = (l + 1) }));
  73. + else
  74. + setlayout(&((Arg) { .v = layouts }));
  75. + } else {
  76. + if(l != layouts && (l - 1)->symbol)
  77. + setlayout(&((Arg) { .v = (l - 1) }));
  78. + else
  79. + setlayout(&((Arg) { .v = &layouts[LENGTH(layouts) - 2] }));
  80. + }
  81. +}
  82. +
  83. +void
  84. destroynotify(XEvent *e)
  85. {
  86. Client *c;
  87. --
  88. 2.7.4