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.

121 lines
3.8 KiB

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. 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. * Initialization
  10. :PROPERTIES:
  11. :header-args: :tangle ../config/xinitrc :comments org
  12. :END:
  13. My workflow includes launching the window manager with *Xinit*[fn:3], without the use of a display manager, controlling *everything* within Emacs.
  14. #+begin_src conf
  15. exec dbus-launch --exit-with-session emacs -mm --debug-init
  16. #+end_src
  17. ** Create a symbolic link(s)
  18. *Xinit*[fn:3] reads its configuration from ~~/.xinitrc~. Override this location with a link to the custom configuration.
  19. #+begin_src emacs-lisp
  20. (dotfiles/symlink "~/.emacs.d/config/xinitrc"
  21. "~/.xinitrc")
  22. #+end_src
  23. * Browser integration
  24. Write out the ~$BROWSER~ variable so other applications can pick up the custom browser.
  25. + Place custom keybindings for browsing behind =SPC b=
  26. + URL with =u=
  27. + URL at point with =p=
  28. + URL at cursor with =c=
  29. #+begin_src emacs-lisp
  30. (setenv "BROWSER" dotfiles/browser)
  31. (dotfiles/leader
  32. "u" '(:ignore t :which-key "Browse")
  33. "uu" '(browse-url :which-key "URL")
  34. "up" '(browse-url-at-point :which-key "Point")
  35. "uc" '(browse-url-at-cursor :which-key "Cursor"))
  36. #+end_src
  37. * Displays detection
  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. * Window manager
  56. Connect our custom hooks and configure the input keys, a custom layer for key capture layers.
  57. + Enable =randr= support
  58. + Pass through to Emacs
  59. + =M-x= to Emacs
  60. + =C-g= to Emacs
  61. + =C-SPC= to Emacs
  62. + Bindings with =S= (Super / Win)
  63. + Reset =S-r=
  64. + Launch =S-&=
  65. + Workspace =S-[1..9]=
  66. #+begin_src emacs-lisp
  67. (use-package exwm
  68. :when (window-system)
  69. :custom (exwm-workspace-show-all-buffers t)
  70. (exwm-input-prefix-keys
  71. '(?\M-x
  72. ?\C-g
  73. ?\C-\ ))
  74. (exwm-input-global-keys
  75. `(([?\s-r] . exwm-reset)
  76. ,@(mapcar (lambda (i)
  77. `(,(kbd (format "s-%d" i)) .
  78. (lambda ()
  79. (interactive)
  80. (exwm-workspace-switch-create ,i))))
  81. (number-sequence 1 9))))
  82. :config (require 'exwm-randr)
  83. (exwm-randr-enable)
  84. (add-hook 'exwm-init-hook #'dotfiles/init-hook)
  85. (add-hook 'exwm-randr-screen-change-hook #'dotfiles/update-display)
  86. (add-hook 'exwm-update-class-hook (lambda () (exwm-workspace-rename-buffer exwm-class-name)))
  87. (dotfiles/update-display)
  88. (exwm-enable))
  89. #+end_src
  90. * Resources
  91. [fn:1] https://github.com/ch11ng/exwm
  92. [fn:2] https://en.wikipedia.org/wiki/X_Window_System
  93. [fn:3] https://en.wikipedia.org/wiki/Xinit
  94. [fn:4] https://wiki.termux.com/wiki/Graphical_Environment