sway-service.scm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
  3. ;;; Copyright © 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
  4. ;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
  5. ;;; Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
  6. ;;; Copyright © 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
  7. ;;; Copyright © 2018 Clément Lassieur <clement@lassieur.org>
  8. ;;; Copyright © 2020, 2021 Joshua Branson <jbranso@dismail.de>
  9. ;;;
  10. ;;; This file is part of GNU Guix.
  11. ;;;
  12. ;;; GNU Guix is free software; you can redistribute it and/or modify
  13. ;;; it under the terms of the GNU General Public License as published by
  14. ;;; the Free Software Foundation, either version 3 of the License, or
  15. ;;; (at your option) any later version.
  16. ;;;
  17. ;;; GNU Guix is distributed in the hope that it will be useful,
  18. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;;; GNU General Public License for more details.
  21. ;;;
  22. ;;; You should have received a copy of the GNU General Public License
  23. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  24. (define-module (sway-service)
  25. #:use-module (guix gexp)
  26. #:use-module (guix records)
  27. #:use-module (guix packages)
  28. #:use-module (guix build-system trivial)
  29. #:use-module (gnu packages admin)
  30. ;; #:autoload (gnu packages ci) (cuirass)
  31. ;; #:autoload (gnu packages version-control) (git)
  32. #:use-module (gnu packages wm)
  33. #:use-module (gnu services)
  34. #:use-module (gnu services base)
  35. #:use-module (gnu services shepherd)
  36. #:use-module (gnu services dbus)
  37. #:use-module (gnu services admin)
  38. #:use-module (gnu system shadow)
  39. #:use-module (ice-9 match)
  40. #:use-module (srfi srfi-1)
  41. #:export (
  42. sway-configuration
  43. sway-configuration?
  44. sway-configuration-sway
  45. sway-configuration-user
  46. sway-configuration-group
  47. sway-configuration-sway-variables
  48. sway-configuration-bindsyms
  49. sway-configuration-raw-content
  50. sway-configuration-file
  51. sway-variables-configuration
  52. sway-variables-configuration?
  53. sway-variables-configuration-background-image
  54. sway-variables-configuration-mod-key
  55. sway-variables-configuration-letter-left
  56. sway-variables-configuration-letter-down
  57. sway-variables-configuration-letter-up
  58. sway-variables-configuration-letter-right
  59. sway-variables-configuration-default-terminal
  60. sway-variables-configuration-application-launcher
  61. sway-variables-configuration-keyboard-layout
  62. sway-variables-configuration-xkb-options
  63. sway-variables-configuration-tap-to-click?
  64. sway-variables-configuration-natural-scroll?
  65. sway-variables-configuration-middle-emulation?
  66. %sway-basic-bindsyms
  67. %sway-moving-around-bindsyms
  68. %sway-layout-bindsyms
  69. %sway-scratchpad-bindsyms
  70. ;; this is (flatten (list all the above %*-bindsyms)
  71. %sway-bindsyms
  72. sway-bindsym
  73. sway-bindsym?
  74. sway-bindsym-whole-window
  75. sway-bindsym-border
  76. sway-bindsym-exclude-titlebar
  77. sway-bindsym-release
  78. sway-bindsym-locked
  79. sway-bindsym-to-code
  80. sway-bindsym-input-device
  81. sway-bindsym-no-warm
  82. sway-bindsym-no-repeat
  83. sway-bindsym-group
  84. sway-bindsym-key-combo
  85. sway-bindsym-command
  86. sway-bindsym-command-arguments
  87. sway-status-bar-configuration
  88. sway-status-bar-configuration?
  89. sway-status-bar-position-configuration
  90. sway-status-bar-status-command-configuration
  91. sway-status-bar-pango-markup-enabled?
  92. sway-status-bar-status-line-color-configuration
  93. sway-status-bar-background-color-configuration
  94. sway-status-bar-inactive-workspace-colors-configuration
  95. sway-service-type
  96. ))
  97. ;;;; Commentary:
  98. ;;; This file provides a shepherd service to run the sway window
  99. ;;; manager.
  100. ;;;; Code:
  101. (define-record-type* <sway-status-bar-configuration>
  102. sway-status-bar-configuration make-sway-status-bar-configuration
  103. sway-status-bar-configuration?
  104. (position sway-status-bar-configuration-position
  105. (default 'top))
  106. (status-command sway-status-bar-configuration-status-command ; string
  107. (default "while date +'%Y-%m-%d %l:%M:%S %p'; do sleep 1; done"))
  108. (pango-markup-enabled? sway-status-bar-configuration-pango-markup-enabled
  109. (default #f))
  110. (status-line-color sway-status-bar-configuration-status-line-color ;string
  111. (default "#ffffff"))
  112. (background-color sway-status-bar-configuration-background-color ;string
  113. (default "#323232"))
  114. (inactive-workspace-colors sway-status-bar-configuration-inactive-workspace-colors ; list of 3 strings
  115. (default '("#32323200 #32323200 #5c5c5c"))))
  116. (define-record-type* <sway-variables-configuration>
  117. sway-variables-configuration make-sway-variables-configuration
  118. sway-variables?
  119. ;; TODO figure out how to set dimensions for desktop background image
  120. (background-image sway-variables-configuration-background-image ;file
  121. (default "Sway_Wallpaper_Blue_1920x1080.png"))
  122. (mod-key sway-variables-configuration-mod
  123. (default "Mod4"))
  124. ;; direction letters
  125. (letter-left sway-variables-configuration-left ;char
  126. (default "h"))
  127. (letter-right sway-variables-configuration-right ;char
  128. (default "l"))
  129. (letter-up sway-variables-configuration-up ;char
  130. (default "k"))
  131. (letter-down sway-variables-configuration-down ;char
  132. (default "j"))
  133. ;; TODO set this default up to be a terminal name
  134. (default-terminal sway-variables-configuration-default-terminal
  135. (default "urxvt")) ;; TODO make this a package object?
  136. ;; set this to dmenu or whatever I am using now
  137. (application-launcher sway-variables-configuration-application-launcher
  138. (default "dmenu")) ;; TODO SET to package object
  139. ;; TODO get this layout from the OS keyboard layout record
  140. ;;list of strings keyboard layouts that you want to use
  141. (keyboard-layout sway-variables-configuration-keyboard-layouts
  142. (default '()))
  143. ;;list of strings of xkb-options that you want like (list "ctrl:swapcaps")
  144. (xkb-options sway-variables-configuration-xkb-options
  145. (default '()))
  146. (tap-to-click? sway-variables-configuration-tap-to-click?
  147. (default #f))
  148. (natural-scroll? sway-variables-configuration-natural-scroll?
  149. (default #t))
  150. (middle-emulation? sway-variables-configuration-middle-emulation?
  151. (default #f)))
  152. (define-record-type* <sway-bindsym>
  153. sway-bindsym make-sway-bindsym
  154. sway-bindsym?
  155. (whole-window sway-bindsym-whole-window
  156. (default #f))
  157. (border sway-bindsym-border
  158. (default #f))
  159. (exclude-titlebar sway-bindsym-exclude-titlebar
  160. (default #f))
  161. (release sway-bindsym-release
  162. (default #f))
  163. (locked sway-bindsym-locked
  164. (default #f))
  165. (to-code sway-bindsym-to-code
  166. (default #f))
  167. (input-device sway-bindsym-input-device
  168. (default #nil))
  169. (no-warn sway-bindsym-no-warn
  170. (default #f))
  171. (no-repeat sway-bindsym-no-repeat
  172. (default #f))
  173. (group sway-bindsym-group
  174. (default #f))
  175. (key-combo sway-bindsym-key-combo
  176. (default ""))
  177. (command sway-bindsym-command ;string or <package>
  178. (default ""))
  179. (command-arguments sway-bindsym-arguments
  180. (default #f)))
  181. (define %sway-basic-bindsyms
  182. (list
  183. (sway-bindsym
  184. (key-combo "$mod+Return")
  185. (command "$term")) ;; set to launch default terminal
  186. (sway-bindsym
  187. (key-combo "$mod+Shift+q")
  188. (command "kill"))
  189. (sway-bindsym
  190. (key-combo "$mod+d")
  191. (command "$menu"))
  192. (sway-bindsym
  193. (key-combo "$mod normal")
  194. (command "normal"))
  195. (sway-bindsym
  196. (key-combo "$mod+Shift+c")
  197. (command "reload"))
  198. (sway-bindsym
  199. (key-combo "$mod+Shift+e")
  200. (command "reload"))))
  201. (define %sway-moving-around-bindsyms
  202. (list
  203. (sway-bindsym
  204. (key-combo "$mod+$left")
  205. (command "focus left"))
  206. (sway-bindsym
  207. (key-combo "$mod+$down")
  208. (command "focus down"))
  209. (sway-bindsym
  210. (key-combo "$mod+$up")
  211. (command "focus up"))
  212. (sway-bindsym
  213. (key-combo "$mod+$right")
  214. (command "focus right"))
  215. (sway-bindsym
  216. (key-combo "$mod+Left")
  217. (command "focus left"))
  218. (sway-bindsym
  219. (key-combo "$mod+Down")
  220. (command "focus down"))
  221. (sway-bindsym
  222. (key-combo "$mod+Up")
  223. (command "focus up"))
  224. (sway-bindsym
  225. (key-combo "$mod+Right")
  226. (command "focus Right"))
  227. ;; Move the focused window with the same, but add Shift
  228. (sway-bindsym
  229. (key-combo "$mod+Shift+$left")
  230. (command "move left"))
  231. (sway-bindsym
  232. (key-combo "$mod+Shift+$down")
  233. (command "move down"))
  234. (sway-bindsym
  235. (key-combo "$mod+Shift+$up")
  236. (command "move up"))
  237. (sway-bindsym
  238. (key-combo "$mod+Shift+$right")
  239. (command "move right"))
  240. (sway-bindsym
  241. (key-combo "$mod+Shift+Left")
  242. (command "move left"))
  243. (sway-bindsym
  244. (key-combo "$mod+Shift+Down")
  245. (command "move down"))
  246. (sway-bindsym
  247. (key-combo "$mod+Shift+Up")
  248. (command "move up"))
  249. (sway-bindsym
  250. (key-combo "$mod+Shift+Right")
  251. (command "move Right"))))
  252. (define %sway-workspace-bindsyms
  253. (list
  254. (sway-bindsym
  255. (key-combo "$mod+1")
  256. (command "workspace number 1"))
  257. (sway-bindsym
  258. (key-combo "$mod+1")
  259. (command "workspace number 2"))
  260. (sway-bindsym
  261. (key-combo "$mod+3")
  262. (command "workspace number 3"))
  263. (sway-bindsym
  264. (key-combo "$mod+4")
  265. (command "workspace number 4"))
  266. (sway-bindsym
  267. (key-combo "$mod+5")
  268. (command "workspace number 5"))
  269. (sway-bindsym
  270. (key-combo "$mod+6")
  271. (command "workspace number 6"))
  272. (sway-bindsym
  273. (key-combo "$mod+7")
  274. (command "workspace number 7"))
  275. (sway-bindsym
  276. (key-combo "$mod+8")
  277. (command "workspace number 8"))
  278. (sway-bindsym
  279. (key-combo "$mod+9")
  280. (command "workspace number 9"))
  281. (sway-bindsym
  282. (key-combo "$mod+10")
  283. (command "workspace number 10"))
  284. ;; Move focused container to workspace
  285. (sway-bindsym
  286. (key-combo "$mod+Shift+1")
  287. (command "move container to workspace 1"))
  288. (sway-bindsym
  289. (key-combo "$mod+Shift+2")
  290. (command "move container to workspace 2"))
  291. (sway-bindsym
  292. (key-combo "$mod+Shift+3")
  293. (command "move container to workspace 3"))
  294. (sway-bindsym
  295. (key-combo "$mod+Shift+4")
  296. (command "move container to workspace 4"))
  297. (sway-bindsym
  298. (key-combo "$mod+Shift+5")
  299. (command "move container to workspace 5"))
  300. (sway-bindsym
  301. (key-combo "$mod+Shift+6")
  302. (command "move container to workspace 6"))
  303. (sway-bindsym
  304. (key-combo "$mod+Shift+7")
  305. (command "move container to workspace 7"))
  306. (sway-bindsym
  307. (key-combo "$mod+Shift+8")
  308. (command "move container to workspace 8"))
  309. (sway-bindsym
  310. (key-combo "$mod+Shift+9")
  311. (command "move container to workspace 9"))
  312. (sway-bindsym
  313. (key-combo "$mod+Shift+10")
  314. (command "move container to workspace 10"))))
  315. (define %sway-layout-bindsyms
  316. (list
  317. (sway-bindsym
  318. (key-combo "$mod+b")
  319. (command "splith"))
  320. ;;bindsym $mod+b splith
  321. (sway-bindsym
  322. (key-combo "$mod+v")
  323. (command "splitv"))
  324. ;; Switch the current container between different layout styles
  325. (sway-bindsym
  326. (key-combo "$mod+s")
  327. (command "layout stacking"))
  328. (sway-bindsym
  329. (key-combo "$mod+w")
  330. (command "layout tabbed"))
  331. (sway-bindsym
  332. (key-combo "$mod+e")
  333. (command "layout toggle split"))
  334. ;; Make the current focus fullscreen
  335. (sway-bindsym
  336. (key-combo "$mod+f")
  337. (command "fullscreen"))
  338. ;; Toggle the current focus between tiling and floating mode
  339. (sway-bindsym
  340. (key-combo "$mod+Shift+space")
  341. (command "floating toggle"))
  342. ;; Swap focus between the tiling area and the floating area
  343. (sway-bindsym
  344. (key-combo "$mod+space")
  345. (command "focus mode_toggle"))
  346. ;; Move focus to the parent container
  347. (sway-bindsym
  348. (key-combo "$mod+a")
  349. (command "focus parent"))
  350. ;; Resizing containers:
  351. ;; TODO how am I handling resizing containers???
  352. ;; TODO let users edit "resize" variable so that they can modify how much each keypress
  353. ;; resizes containers.
  354. ;; this code is hardcoded into the service definition
  355. ;; mode "resize" {
  356. ;; # left will shrink the containers width
  357. ;; # right will grow the containers width
  358. ;; # up will shrink the containers height
  359. ;; # down will grow the containers height
  360. ;; bindsym $left resize shrink width 10px
  361. ;; bindsym $down resize grow height 10px
  362. ;; bindsym $up resize shrink height 10px
  363. ;; bindsym $right resize grow width 10px
  364. ;; # Ditto, with arrow keys
  365. ;; bindsym Left resize shrink width 10px
  366. ;; bindsym Down resize grow height 10px
  367. ;; bindsym Up resize shrink height 10px
  368. ;; bindsym Right resize grow width 10px
  369. ;; # Return to default mode
  370. ;; bindsym Return mode "default"
  371. ;; bindsym Escape mode "default"
  372. ;; }
  373. ;; bindsym $mod+r mode "resize"
  374. (sway-bindsym
  375. (key-combo "$mod+r")
  376. (command "\"resize\""))))
  377. (define %sway-scratchpad-bindsyms
  378. (list
  379. (sway-bindsym
  380. (key-combo "$mod+Shift+minus")
  381. (command "move scratchpad"))
  382. ;; Show the next scratchpad window or hide the focused scratchpad window.
  383. ;; If there are multiple scratchpad windows, this command cycles through them.
  384. (sway-bindsym
  385. (key-combo "$mod+minus")
  386. (command "scratchpad show"))))
  387. (define (flatten . lst)
  388. "Return a list that recursively concatenates all sub-lists of LST."
  389. (define (flatten1 head out)
  390. (if (list? head)
  391. (fold-right flatten1 out head)
  392. (cons head out)))
  393. (fold-right flatten1 '() lst))
  394. (define %sway-bindsyms
  395. (flatten (list
  396. %sway-basic-bindsyms
  397. %sway-layout-bindsyms
  398. %sway-workspace-bindsyms
  399. %sway-moving-around-bindsyms
  400. %sway-scratchpad-bindsyms)))
  401. (define-record-type* <sway-configuration>
  402. sway-configuration make-sway-configuration
  403. sway-configuration?
  404. (sway sway-configuration-sway ;package
  405. (default sway))
  406. (user sway-configuration-user ;string
  407. (default "sway"))
  408. (group sway-configuration-group ;string
  409. (default "users"))
  410. (variables sway-configuration-variables
  411. (default (sway-variables-configuration)))
  412. (bindsyms sway-configuration-bindsyms
  413. (default %sway-bindsyms))
  414. (status-bar sway-configuration-status-bar
  415. (default (sway-status-bar-configuration)))
  416. (raw-content sway-configuration-raw-content
  417. (default ""))
  418. (file sway-configuration-file ;file-like object
  419. (default #f)))
  420. (define sway-variables-configuration->list
  421. (match-lambda
  422. (($ <sway-variables-configuration> background-image mod-key letter-left letter-down letter-up letter-right
  423. default-terminal application-launcher keyboard-layout xkb-options
  424. tap-to-click? natural-scroll? middle-emulation?)
  425. (list
  426. "### Variables\n"
  427. "# Logo key. Use Mod1 for Alt\n"
  428. "set $mod " mod-key "\n"
  429. "# Home row direction keys, like vim\n"
  430. "set $left " letter-left "\n"
  431. "set $down " letter-down "\n"
  432. "set $up " letter-up "\n"
  433. "set $right " letter-right "\n"
  434. "set $term " default-terminal "\n" ;;TODO potentially use a gexp to point to default-terminal package
  435. ;; TODO deal with application-launcher
  436. "### Output configuration\n"
  437. "# Default Wallpaper\n"
  438. "output * bg " background-image " fill\n" ;;TODO use a gexp to copy the background image into the store
  439. ;; TODO deal with swayidle and sway lock
  440. "### Input configuration\n"
  441. (cond [(or tap-to-click? natural-scroll? middle-emulation? (not (null? keyboard-layout))
  442. (not (null? xkb-options)))
  443. (list
  444. "input * " "{ \n"
  445. (if tap-to-click?
  446. "\t tap enabled\n"
  447. "")
  448. (if natural-scroll?
  449. "\t natural_scroll enabled\n"
  450. "")
  451. (if middle-emulation?
  452. "\t middle_emulation enabled\n"
  453. "")
  454. ;; TODO xkb-layout should be gotten from the keyboard layout,
  455. ;; which should specify it in the environment The keymap can
  456. ;; also be configured using environment variables
  457. ;; (XKB_DEFAULT_LAYOUT, XKB_DEFAULT_VARIANT, etc.) when starting
  458. ;; sway, with config options taking precedence over environment
  459. ;; variables.
  460. ;; TODO xkb-layout the arch linux wiki page shows
  461. ;; this https://wiki.archlinux.org/index.php/Sway#Keymap input *
  462. ;; { xkb_layout "us,de,ru" xkb_variant "colemak,,typewriter"
  463. ;; xkb_options "grp:win_space_toggle" }
  464. (cond [(not (null? xkb-options))
  465. (list
  466. "xkb_options "
  467. (substring (let loop ([list xkb-options])
  468. (cond [(null? list)
  469. ""]
  470. [else (string-append "," (car list)
  471. (loop (cdr list)))])) 1))]
  472. [else ""])
  473. "\n} \n" ;; end input
  474. )]
  475. [else ""])
  476. ))))
  477. ;; <sway-bindsym> -> string
  478. ;; consider renaming to sway-bindsym->string
  479. (define (sway-bindsym->string sway-bindsym)
  480. (let* ([command (sway-bindsym-command sway-bindsym)]
  481. [key-combo
  482. (cond [(package? command)
  483. ;;TODO gexp <package> -> string /gnu/store/stahesunteah/bin/<package>
  484. ]
  485. [else (sway-bindsym-key-combo sway-bindsym)])])
  486. (string-append key-combo " " command "\n")))
  487. ;; list of <sway-bindsym> -> string
  488. (define (sway-bindsyms->list list)
  489. (let loop ([list (flatten list)])
  490. (cond [(null? list)
  491. '()]
  492. [else
  493. (cons (sway-bindsym->string (car list))
  494. (loop (cdr list)))])))
  495. ;; pango-markup-enabled? Todo
  496. (define sway-status-bar-configuration->list
  497. (match-lambda
  498. (($ <sway-status-bar-configuration> position status-command pango-markup-enabled?
  499. status-line-color background-color
  500. inactive-workspace-colors)
  501. (list
  502. "#\n"
  503. "# Status Bar:\n"
  504. "#\n"
  505. "# Read man 5 sway-bar-configuration for more information about this section."
  506. "bar {\n"
  507. "\t position " (symbol->string position) "\n"
  508. "\t # When the status_command prints a new line to stdout, swaybar updates.\n"
  509. "\t # The default just shows the current date and time.\n"
  510. "\t status_command " status-command "\n"
  511. "\t colors {\n"
  512. "\t\t statusline " status-line-color "\n"
  513. "\t\t background " background-color "\n"
  514. "\t\t inactive_workspace "
  515. (let loop ([list inactive-workspace-colors])
  516. (cond [(null? list)
  517. ""]
  518. [else (string-append (car list) " "
  519. (loop (cdr list)))]))
  520. "\n"
  521. "\t }\n"
  522. "}\n"
  523. ))))
  524. ;; TODO deal with a sway config-file
  525. (define sway-configuration->list
  526. (match-lambda
  527. (($ <sway-configuration> sway user group variables
  528. bindsyms status-bar raw-content
  529. file)
  530. (flatten
  531. (list
  532. (sway-variables-configuration->list variables)
  533. (sway-bindsyms->list bindsyms)
  534. ;; Todo
  535. (sway-status-bar-configuration->list status-bar)
  536. )))))
  537. ;; Maybe put this code in a guix test?
  538. ;; (define config (sway-configuration
  539. ;; (variables
  540. ;; (sway-variables-configuration
  541. ;; (letter-left "n")
  542. ;; (letter-right "s")
  543. ;; (letter-up "t")
  544. ;; (letter-down "h")
  545. ;; (mod-key "Mod1")
  546. ;; (default-terminal "allcritty")
  547. ;; (xkb-options (list "ctrl:swapcaps"
  548. ;; "shift:breaks_caps"))))
  549. ;; (bindsyms
  550. ;; (list
  551. ;; %sway-basic-bindsyms
  552. ;; %sway-moving-around-bindsyms
  553. ;; (sway-bindsym (key-combo "$mod+Shift+Return")
  554. ;; (command "$term -e fish"))))
  555. ;; (status-bar
  556. ;; (sway-status-bar-configuration
  557. ;; (status-command "echo 'hello world!'")
  558. ;; (status-line-color "blue")
  559. ;; (inactive-workspace-colors (list "red" "green" "yellow"))))))
  560. ;;
  561. ;; (display (let loop ([list (sway-configuration->list config)])
  562. ;; (cond [(null? list)
  563. ;; ""]
  564. ;; [else (string-append (car list)
  565. ;; (loop (cdr list)))])))
  566. ;; For now I am assuming that this is correct.
  567. (define (default-sway-config config)
  568. ;; (match-record
  569. ;; config
  570. ;; <sway-configuration>
  571. ;; (sway user group variables bindsyms status-bar raw-content file)
  572. ;; ;; (apply mixed-text-file "config.in"
  573. ;; ;; (flatten
  574. ;; ;; (sway-configuration->list config)))
  575. ;; ;; TODO this won't work if I want to use gexps involving paths to executables.
  576. ;; )
  577. (plain-file "config.in"
  578. (apply string-append (sway-configuration->list config))))
  579. (define (sway-activation config)
  580. (match-record config
  581. <sway-configuration>
  582. (sway file)
  583. #~(begin
  584. (use-modules (guix build utils))
  585. ;; (format #t "creating nginx log directory '~a'~%" #$log-directory)
  586. ;; (mkdir-p #$log-directory)
  587. ;; Start-up logs. Once configuration is loaded, nginx switches to
  588. ;; log-directory.
  589. ;; do something with recording sway's logs.
  590. ;;(mkdir-p (string-append #$run-directory "/logs"))
  591. ;; Check configuration file syntax.
  592. (system* (string-append #$sway "/bin/sway")
  593. "-c" #$(or file
  594. (default-sway-config config))))))
  595. (define (sway-shepherd-service config)
  596. "Return a <shepherd-service> for the Sway service with CONFIG."
  597. (let* ([sway (sway-configuration-sway config)]
  598. [user (sway-configuration-user config)]
  599. [group (sway-configuration-group config)]
  600. [file (sway-configuration-file config)])
  601. (list (shepherd-service
  602. (documentation "Run Sway.")
  603. (provision '(sway))
  604. (requirement '(user-processes dbus-system elogind udev virtual-terminal syslogd))
  605. ;;(requirement '(guix-daemon networking))
  606. (start #~(make-forkexec-constructor
  607. ;; TODO change this line to
  608. ;; exec dbus-run-session sway
  609. ;; should we un-gexp the (string-append?
  610. ;; they do it here
  611. ;; [[file:~/prog/gnu/guix/guix-src/gnu/services/base.scm::(system* #$(file-append guix "/bin/guix") "archive"][here]]
  612. (list (string-append #$sway "/bin/sway")
  613. ;; should this be a '("-c")
  614. ;; [[file:~/prog/gnu/guix/guix-src/gnu/services/networking.scm::'("-g")]['("-g")]]
  615. "-c"
  616. #$(or file
  617. (default-sway-config config)))
  618. ;; #:environment-variables
  619. ;; (list "GIT_SSL_CAINFO=/etc/ssl/certs/ca-certificates.crt"
  620. ;; (string-append "GIT_EXEC_PATH=" #$git
  621. ;; "/libexec/git-core"))
  622. #:user #$user
  623. ;;#:group #$group
  624. ;;#:log-file #$log-file
  625. ))
  626. (stop #~(make-kill-destructor
  627. (list (string-append #$sway "/bin/swaymsg")
  628. "exit")
  629. #:user #$user))))))
  630. (define sway-service-type
  631. (service-type (name 'sway)
  632. (extensions (list
  633. ;; (service-extension profile-service-type ;for 'info sway'
  634. ;; (compose list sway-configuration-sway shepherd-root-service-type))
  635. (service-extension polkit-service-type sway-service-type)
  636. ;; all gnome, xfce, mate, use this profile-service-type, which I'm guessing means
  637. ;; to start the service after the user has logged in.
  638. (service-extension profile-service-type
  639. (compose list sway-configuration-sway))
  640. ;; activation service type is a procedure that returns a gexp which is a code snippet to run at
  641. ;; activation time. example at boot
  642. (service-extension activation-service-type sway-activation)
  643. ;;(service-extension account-service-type sway-account)
  644. ;; if people define %desktop-services, then we don't need it.
  645. ;; if this service goes in the services/wm.scm, include elogind
  646. ;;(service-extension elogind-service-type)
  647. ))
  648. (default-value (sway-configuration))
  649. (description "Run the sway window manager.")))