I showed you my source code, pls respond
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.

179 lines
5.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #+TITLE: Desktop
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+PROPERTY: header-args:emacs-lisp :tangle desktop.el :comments org
  5. #+PROPERTY: header-args :results silent :eval no-export :comments org
  6. #+OPTIONS: num:nil toc:nil todo:nil tasks:nil tags:nil
  7. #+OPTIONS: skip:nil author:nil email:nil creator:nil timestamp:nil
  8. #+ATTR_ORG: :width 420px
  9. #+ATTR_HTML: :width 420px
  10. #+ATTR_LATEX: :width 420px
  11. [[../docs/images/modules-desktop.png]]
  12. I use Emacs as a Desktop Environment with the *EXWM*[fn:1] package. It allows Emacs to function as a complete tiling window manager for *X11*[fn:2].
  13. * Initialization
  14. :PROPERTIES:
  15. :header-args: :tangle ../config/xinitrc :comments org
  16. :END:
  17. My workflow includes launching the window manager with *Xinit*[fn:3], without the use of a display manager, controlling *everything* within Emacs. In addition, compton is used as a display compositor, and slock for a screen lock.
  18. #+begin_src conf
  19. compton &
  20. xss-lock -- slock &
  21. # FIXME! https://github.com/ch11ng/exwm/issues/210#issuecomment-350044271
  22. exec dbus-launch --exit-with-session emacs -mm --debug-init
  23. #+end_src
  24. ** Create a symbolic link(s)
  25. *Xinit*[fn:3] reads its configuration from ~~/.xinitrc~. Override this location with a link to the custom configuration.
  26. #+begin_src emacs-lisp
  27. (dotfiles/symlink "~/.emacs.d/config/xinitrc"
  28. "~/.xinitrc")
  29. #+end_src
  30. ** Desktop environment
  31. Use the *desktop-environment* package to automatically bind well-known programs for controlling the volume, brightness, media playback, and many other XF86 functionality bindings.
  32. #+begin_src emacs-lisp
  33. (use-package desktop-environment
  34. :after exwm
  35. :custom (desktop-environment-brightness-small-increment "2%+")
  36. (desktop-environment-brightness-small-decrement "2%-")
  37. (desktop-environment-brightness-normal-decrement "5%-")
  38. (desktop-environment-brightness-normal-decrement "5%-")
  39. (desktop-environment-volume-small-increment "2%+")
  40. (desktop-environment-volume-small-decrement "2%-")
  41. (desktop-environment-volume-normal-increment "5%+")
  42. (desktop-environment-volume-normal-decrement "5%-")
  43. :config (desktop-environment-mode))
  44. #+end_src
  45. #+RESULTS:
  46. : t
  47. ** Keyboard tweaks
  48. :PROPERTIES:
  49. :header-args: conf :tangle ../config/xmodmap
  50. :END:
  51. Use *XModmap* to swap CapsLock and Ctrl to keep common bindings on the home row.
  52. #+begin_src conf
  53. clear lock
  54. clear control
  55. keycode 66 = Control_L
  56. add control = Control_L
  57. add Lock = Control_R
  58. #+end_src
  59. #+begin_src emacs-lisp
  60. (dotfiles/symlink "~/.emacs.d/config/xmodmap"
  61. "~/.Xmodmap")
  62. #+end_src
  63. #+RESULTS:
  64. * Browser integration
  65. Write out the ~$BROWSER~ variable so other applications can pick up the custom browser.
  66. + Place custom keybindings for browsing behind =SPC b=
  67. + URL with =u=
  68. + URL at point with =p=
  69. + URL at cursor with =c=
  70. #+begin_src emacs-lisp
  71. (setenv "BROWSER" dotfiles/browser)
  72. (dotfiles/leader
  73. "u" '(:ignore t :which-key "Browse")
  74. "uu" '(browse-url :which-key "URL")
  75. "up" '(browse-url-at-point :which-key "Point")
  76. "uc" '(browse-url-at-cursor :which-key "Cursor"))
  77. #+end_src
  78. * Displays detection
  79. When the window manager first launches the ~init-hook~ executes, allowing us to define some custom logic.
  80. + Display time and date
  81. + Display battery info (if available)
  82. In my personal configuration, I do not want the battery or time displayed within Emacs when it's not running as desktop environment because that information is typically already available.
  83. #+begin_src emacs-lisp
  84. (defun dotfiles/init-hook ()
  85. (exwm-workspace-switch-create 1)
  86. (setq display-time-and-date t)
  87. (display-battery-mode 1)
  88. (display-time-mode 1))
  89. #+end_src
  90. Using =autorandr= with pre configured profiles, switching screens (AKA hot plugging) is also handled through a hook.
  91. #+begin_src emacs-lisp
  92. (defun dotfiles/update-display ()
  93. "Update the displays by forcing a change through autorandr."
  94. (dotfiles/run-in-background "autorandr --change --force"))
  95. #+end_src
  96. * Window manager
  97. Connect our custom hooks and configure the input keys, a custom layer for key capture layers.
  98. + Enable =randr= support
  99. + Pass through to Emacs
  100. + =M-x= to Emacs
  101. + =C-g= to Emacs
  102. + =C-SPC= to Emacs
  103. + Bindings with =S= (Super / Win)
  104. + Reset =S-r=
  105. + Launch =S-&=
  106. + Workspace =S-[1..9]=
  107. #+begin_src emacs-lisp
  108. (use-package exwm
  109. :when (window-system)
  110. :custom (exwm-workspace-show-all-buffers t)
  111. (exwm-input-prefix-keys
  112. '(?\M-x
  113. ?\C-g
  114. ?\C-\ ))
  115. (exwm-input-global-keys
  116. `(([?\s-r] . exwm-reset)
  117. ,@(mapcar (lambda (i)
  118. `(,(kbd (format "s-%d" i)) .
  119. (lambda ()
  120. (interactive)
  121. (exwm-workspace-switch-create ,i))))
  122. (number-sequence 1 9))))
  123. :config (require 'exwm-randr)
  124. (exwm-randr-enable)
  125. (add-hook 'exwm-init-hook #'dotfiles/init-hook)
  126. (add-hook 'exwm-randr-screen-change-hook #'dotfiles/update-display)
  127. (add-hook 'exwm-update-class-hook (lambda () (exwm-workspace-rename-buffer exwm-class-name)))
  128. (dotfiles/update-display)
  129. (dotfiles/run-in-background "nitrogen --restore") ;; Update the wallpaper.
  130. (exwm-enable))
  131. #+end_src
  132. * Footnotes
  133. [fn:1] https://github.com/ch11ng/exwm
  134. [fn:2] https://en.wikipedia.org/wiki/X_Window_System
  135. [fn:3] https://en.wikipedia.org/wiki/Xinit
  136. [fn:4] https://wiki.termux.com/wiki/Graphical_Environment