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.

150 lines
4.5 KiB

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. 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].
  9. * Profile
  10. :PROPERTIES:
  11. :header-args: :tangle ../config/profile :comments org
  12. :END:
  13. Ensure that ~~/.local/bin~ is added to the =$PATH= variable.
  14. #+begin_src shell
  15. PATH=$PATH:~/.local/bin
  16. export PATH
  17. #+end_src
  18. When launching into a new session on ~TTY1~, if the display server is not running, run *StartX*[fn:3]. This will launch the window manager.
  19. #+begin_src shell
  20. if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
  21. exec startx
  22. fi
  23. #+end_src
  24. * Startup
  25. :PROPERTIES:
  26. :header-args: :tangle ../config/xinitrc :comments org
  27. :END:
  28. My workflow includes launching the window manager with *Xinit*[fn:3], without the use of a display manager, controlling *everything* within Emacs.
  29. #+begin_src conf
  30. exec dbus-launch --exit-with-session emacs -mm --debug-init
  31. #+end_src
  32. * Browser
  33. Write out the ~$BROWSER~ variable so other applications can pick up the custom browser.
  34. #+begin_src emacs-lisp
  35. (setenv "BROWSER" dotfiles/browser)
  36. #+end_src
  37. * Displays
  38. When the window manager first launches the ~init-hook~ executes, allowing us to define some custom logic.
  39. + Display time and date
  40. + Display battery info (if available)
  41. 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.
  42. #+begin_src emacs-lisp
  43. (defun dotfiles/init-hook ()
  44. (exwm-workspace-switch-create 1)
  45. (setq display-time-and-date t)
  46. (display-battery-mode 1)
  47. (display-time-mode 1))
  48. #+end_src
  49. Using =autorandr= with pre configured profiles, switching screens (AKA hot plugging) is also handled through a hook.
  50. #+begin_src emacs-lisp
  51. (defun dotfiles/update-display ()
  52. "Update the displays by forcing a change through autorandr."
  53. (dotfiles/run-in-background "autorandr --change --force"))
  54. #+end_src
  55. * Methods
  56. Define a method to run an external process, allowing us to launch any application on a new process without interferring with Emacs.
  57. #+begin_src emacs-lisp
  58. (defun dotfiles/run (command)
  59. "Run an external process."
  60. (interactive (list (read-shell-command "λ ")))
  61. (start-process-shell-command command nil command))
  62. #+end_src
  63. Apply methods to the current call process to avoid issues with hooks.
  64. #+begin_src emacs-lisp
  65. (defun dotfiles/run-in-background (command)
  66. (let ((command-parts (split-string command "[ ]+")))
  67. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  68. #+end_src
  69. Place keybindings for executing shell commands behind =SPC x=.
  70. + Run shell commands with =x=
  71. + Run async shell commands with =z=
  72. #+begin_src emacs-lisp
  73. (dotfiles/leader
  74. "x" '(:ignore t :which-key "Run")
  75. "xx" '(dotfiles/run :which-key "Run")
  76. "xz" '(async-shell-command :which-key "Async"))
  77. #+end_src
  78. * Configuration
  79. Connect our custom hooks and configure the input keys, a custom layer for key capture layers.
  80. + Enable =randr= support
  81. + Pass through to Emacs
  82. + =M-x= to Emacs
  83. + =C-g= to Emacs
  84. + =C-SPC= to Emacs
  85. + Bindings with =S= (Super / Win)
  86. + Reset =S-r=
  87. + Launch =S-&=
  88. + Workspace =S-[1..9]=
  89. #+begin_src emacs-lisp
  90. (use-package exwm
  91. :custom (exwm-workspace-show-all-buffers t)
  92. (exwm-input-prefix-keys
  93. '(?\M-x
  94. ?\C-g
  95. ?\C-\ ))
  96. (exwm-input-global-keys
  97. `(([?\s-r] . exwm-reset)
  98. ,@(mapcar (lambda (i)
  99. `(,(kbd (format "s-%d" i)) .
  100. (lambda ()
  101. (interactive)
  102. (exwm-workspace-switch-create ,i))))
  103. (number-sequence 1 9))))
  104. :config (require 'exwm-randr)
  105. (exwm-randr-enable)
  106. (add-hook 'exwm-init-hook #'dotfiles/init-hook)
  107. (add-hook 'exwm-randr-screen-change-hook #'dotfiles/update-display)
  108. (add-hook 'exwm-update-class-hook (lambda () (exwm-workspace-rename-buffer exwm-class-name)))
  109. (dotfiles/update-display)
  110. (exwm-enable))
  111. #+end_src
  112. * Resources
  113. [fn:1] https://github.com/ch11ng/exwm
  114. [fn:2] https://en.wikipedia.org/wiki/X_Window_System
  115. [fn:3] https://en.wikipedia.org/wiki/Xinit