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.

176 lines
5.4 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/desktop-example.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. ** Keyboard tweaks
  46. :PROPERTIES:
  47. :header-args: conf :tangle ../config/xmodmap
  48. :END:
  49. Use *XModmap* to swap CapsLock and Ctrl to keep common bindings on the home row.
  50. #+begin_src conf
  51. clear lock
  52. clear control
  53. keycode 66 = Control_L
  54. add control = Control_L
  55. add Lock = Control_R
  56. #+end_src
  57. #+begin_src emacs-lisp
  58. (dotfiles/symlink "~/.emacs.d/config/xmodmap"
  59. "~/.Xmodmap")
  60. #+end_src
  61. #+RESULTS:
  62. * Browser integration
  63. Write out the ~$BROWSER~ variable so other applications can pick up the custom browser.
  64. + Place custom keybindings for browsing behind =SPC b=
  65. + URL with =u=
  66. + URL at point with =p=
  67. + URL at cursor with =c=
  68. #+begin_src emacs-lisp
  69. (setenv "BROWSER" dotfiles/browser)
  70. (dotfiles/leader
  71. "u" '(:ignore t :which-key "Browse")
  72. "uu" '(browse-url :which-key "URL")
  73. "up" '(browse-url-at-point :which-key "Point")
  74. "uc" '(browse-url-at-cursor :which-key "Cursor"))
  75. #+end_src
  76. * Displays detection
  77. When the window manager first launches the ~init-hook~ executes, allowing us to define some custom logic.
  78. + Display time and date
  79. + Display battery info (if available)
  80. 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.
  81. #+begin_src emacs-lisp
  82. (defun dotfiles/init-hook ()
  83. (exwm-workspace-switch-create 1)
  84. (setq display-time-and-date t)
  85. (display-battery-mode 1)
  86. (display-time-mode 1))
  87. #+end_src
  88. Using =autorandr= with pre configured profiles, switching screens (AKA hot plugging) is also handled through a hook.
  89. #+begin_src emacs-lisp
  90. (defun dotfiles/update-display ()
  91. "Update the displays by forcing a change through autorandr."
  92. (dotfiles/run-in-background "autorandr --change --force"))
  93. #+end_src
  94. * Window manager
  95. Connect our custom hooks and configure the input keys, a custom layer for key capture layers.
  96. + Enable =randr= support
  97. + Pass through to Emacs
  98. + =M-x= to Emacs
  99. + =C-g= to Emacs
  100. + =C-SPC= to Emacs
  101. + Bindings with =S= (Super / Win)
  102. + Reset =S-r=
  103. + Launch =S-&=
  104. + Workspace =S-[1..9]=
  105. #+begin_src emacs-lisp
  106. (use-package exwm
  107. :when (window-system)
  108. :custom (exwm-workspace-show-all-buffers t)
  109. (exwm-input-prefix-keys
  110. '(?\M-x
  111. ?\C-g
  112. ?\C-\ ))
  113. (exwm-input-global-keys
  114. `(([?\s-r] . exwm-reset)
  115. ,@(mapcar (lambda (i)
  116. `(,(kbd (format "s-%d" i)) .
  117. (lambda ()
  118. (interactive)
  119. (exwm-workspace-switch-create ,i))))
  120. (number-sequence 1 9))))
  121. :config (require 'exwm-randr)
  122. (exwm-randr-enable)
  123. (add-hook 'exwm-init-hook #'dotfiles/init-hook)
  124. (add-hook 'exwm-randr-screen-change-hook #'dotfiles/update-display)
  125. (add-hook 'exwm-update-class-hook (lambda () (exwm-workspace-rename-buffer exwm-class-name)))
  126. (dotfiles/update-display)
  127. (dotfiles/run-in-background "nitrogen --restore") ;; Update the wallpaper.
  128. (exwm-enable))
  129. #+end_src
  130. * Footnotes
  131. [fn:1] https://github.com/ch11ng/exwm
  132. [fn:2] https://en.wikipedia.org/wiki/X_Window_System
  133. [fn:3] https://en.wikipedia.org/wiki/Xinit
  134. [fn:4] https://wiki.termux.com/wiki/Graphical_Environment