openbox.scm
1 | ;;; Guix Home Manager. |
2 | ;;; |
3 | ;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu> |
4 | ;;; |
5 | ;;; This program is free software: you can redistribute it and/or modify |
6 | ;;; it under the terms of the GNU General Public License as published by |
7 | ;;; the Free Software Foundation, either version 3 of the License, or |
8 | ;;; (at your option) any later version. |
9 | ;;; |
10 | ;;; This program is distributed in the hope that it will be useful, |
11 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | ;;; GNU General Public License for more details. |
14 | ;;; |
15 | ;;; You should have received a copy of the GNU General Public License |
16 | ;;; along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | |
18 | (define-module (home openbox) |
19 | #:use-module (guix build utils) |
20 | #:use-module (guix build-system trivial) |
21 | #:use-module (guix gexp) |
22 | #:use-module (guix licenses) |
23 | #:use-module (guix packages) |
24 | #:use-module (guix records) |
25 | #:use-module (gnu packages lxde) |
26 | #:use-module (ice-9 match) |
27 | #:export (openbox-configuration |
28 | openbox-configuration? |
29 | openbox-configuration-autostart |
30 | openbox-configuration-environ |
31 | openbox-configuration-menu |
32 | openbox-configuration-rc |
33 | |
34 | openbox-menu |
35 | openbox-menu-id |
36 | openbox-menu-label |
37 | opebnox-menu-elements |
38 | |
39 | openbox-element-menu |
40 | openbox-element-execute |
41 | |
42 | openbox-home)) |
43 | |
44 | (define-record-type* <openbox-configuration> |
45 | openbox-configuration make-openbox-configuration |
46 | openbox-configuration? |
47 | (autostart openbox-configuration-autostart |
48 | (default #f)) |
49 | (environ openbox-configuration-environ |
50 | (default #f)) |
51 | (menus openbox-configuration-menus |
52 | (default '())) |
53 | (root-elements openbox-configuration-root-elements |
54 | (default '())) |
55 | (rc openbox-configuration-rc |
56 | (default #f))) |
57 | |
58 | (define-record-type* <openbox-menu> |
59 | openbox-menu make-openbox-menu |
60 | openbox-menu? |
61 | (id openbox-menu-id) |
62 | (label openbox-menu-label) |
63 | (elements openbox-menu-elements)) |
64 | |
65 | (define-record-type* <openbox-element-menu> |
66 | openbox-element-menu make-openbox-element-menu |
67 | openbox-element-menu? |
68 | (id openbox-element-menu-id)) |
69 | |
70 | (define-record-type* <openbox-element-execute> |
71 | openbox-element-execute make-openbox-element-execute |
72 | openbox-element-execute? |
73 | (label openbox-element-execute-label) |
74 | (command openbox-element-execute-command) |
75 | (notify? openbox-element-execute-notify? |
76 | (default #t))) |
77 | |
78 | (define (generate-openbox-menu menus root-menu) |
79 | (define (element->item element) |
80 | (match element |
81 | (($ <openbox-element-menu> id) |
82 | `(menu (@ (id ,id)))) |
83 | (($ <openbox-element-execute> label command notify?) |
84 | `(item (@ (label ,label)) |
85 | (action (@ (name "Execute")) |
86 | (command ,command) |
87 | ,@(if notify? '(startupnotify (enabled "yes")) '())))))) |
88 | #~(begin |
89 | (use-modules (sxml simple)) |
90 | (with-output-to-file #$output |
91 | (lambda _ |
92 | (sxml->xml |
93 | `(openbox_menu (@ (xmlns "http://openbox.org/3.4/menu")) |
94 | #$(map |
95 | (lambda (menu) |
96 | `(menu (@ (id ,(openbox-menu-id menu)) (label ,(openbox-menu-label menu))) |
97 | ,(map element->item (openbox-menu-elements menu)))) |
98 | menus) |
99 | (menu (@ (id "root-menu") (label "Openbox 3")) |
100 | #$(map element->item root-menu)))))))) |
101 | |
102 | (define (openbox-autostart autostart) |
103 | (match autostart |
104 | (#f (plain-file "autostart" "")) |
105 | (_ autostart))) |
106 | |
107 | (define (openbox-environment environ) |
108 | (match environ |
109 | (#f (plain-file "environ" "")) |
110 | (_ environ))) |
111 | |
112 | (define (openbox-rc rc) |
113 | (match rc |
114 | (#f (plain-file "rc.xml" "")) |
115 | (_ rc))) |
116 | |
117 | (define (openbox-home config) |
118 | (computed-file "openbox-home" |
119 | (match config |
120 | (($ <openbox-configuration> autostart environ menus root-elements rc) |
121 | #~(let ((menu.xml #$(computed-file "menu.xml" (generate-openbox-menu menus root-elements))) |
122 | (autostart #$(openbox-autostart autostart)) |
123 | (environ #$(openbox-environment environ)) |
124 | (rc #$(openbox-rc rc)) |
125 | (openbox-dir (string-append #$output "/.config/openbox"))) |
126 | (use-modules (guix build utils)) |
127 | (mkdir-p openbox-dir) |
128 | (copy-file autostart (string-append openbox-dir "/autostart")) |
129 | (copy-file environ (string-append openbox-dir "/environment")) |
130 | (copy-file menu.xml (string-append openbox-dir "/menu.xml")) |
131 | (copy-file rc (string-append openbox-dir "/rc.xml"))))) |
132 | #:options |
133 | '(#:local-build? #t |
134 | #:modules ((guix build utils))))) |