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.

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