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.

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