i3wm.el 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ;;; i3wm.el --- i3wm integration library
  2. ;; Copyright (C) 2016 Samuel Flint
  3. ;; Author: Samuel W. Flint <swflint@flintfam.org>
  4. ;; Version: 0.5
  5. ;; Keywords: convenience, extensions
  6. ;; URL: https://git.flintfam.org/swf-projects/emacs-i3
  7. ;;; Commentary:
  8. ;;
  9. ;; This provides an interface to the i3 window manager, with a few
  10. ;; pre-built accessors to the various i3 commands.
  11. ;;; Code:
  12. (require 'json)
  13. ;;; Primitive functions:
  14. (defun i3wm-command (command &rest arguments)
  15. "Execute the given COMMAND with the given ARGUMENTS."
  16. (json-read-from-string
  17. (shell-command-to-string
  18. (format "i3-msg %s" (shell-quote-argument (apply #'format command arguments))))))
  19. (defun i3wm-get-workspaces ()
  20. "List all workspaces."
  21. (json-read-from-string
  22. (shell-command-to-string "i3-msg -t get_workspaces")))
  23. (defun i3wm-get-outputs ()
  24. "List all outputs."
  25. (json-read-from-string
  26. (shell-command-to-string "i3-msg -t get_outputs")))
  27. (defun i3wm-get-version ()
  28. "Retrieve i3 version."
  29. (json-read-from-string
  30. (shell-command-to-string "i3-msg -t get_version")))
  31. ;;; i3 commands
  32. (defun i3wm-exec (program)
  33. "Execute the given PROGRAM."
  34. (i3wm-command "exec %s" program))
  35. (defun i3wm-exec-no-startup-id (program)
  36. "Execute the given PROGRAM with --no-startup-id."
  37. (i3wm-command "exec --no-startup-id %s" program))
  38. (defun i3wm-workspace (workspace)
  39. "Switch to the given i3 WORKSPACE."
  40. (i3wm-command "workspace %s" workspace))
  41. (defun i3wm-workspace-numbered (number)
  42. "Switch to the workspace with the given NUMBER."
  43. (i3wm-command "workspace number %d" number))
  44. (defun i3wm-workspace-next ()
  45. "Switch to the next workspace."
  46. (i3wm-command "workspace next"))
  47. (defun i3wm-workspace-prev ()
  48. "Switch to the previous workspace."
  49. (i3wm-command "workspace prev"))
  50. (defun i3wm-split-horizontally ()
  51. "Split the current container horizontally."
  52. (i3wm-command "split h"))
  53. (defun i3wm-split-vertically ()
  54. "Split the current container vertically."
  55. (i3wm-command "split v"))
  56. (defun i3wm-stacking ()
  57. "Switch to a stacking layout."
  58. (i3wm-command "layout stacking"))
  59. (defun i3wm-tabbed ()
  60. "Switch to a tabbed layout."
  61. (i3wm-command "layout tabbed"))
  62. (defun i3wm-fullscreen ()
  63. "Switch to a fullscreen layout."
  64. (i3wm-command "fullscreen toggle"))
  65. (defun i3wm-floating ()
  66. "Toggle container floating."
  67. (i3wm-command "floating toggle"))
  68. ;; Interactive commands
  69. ;;;###autoload
  70. (defun i3wm-switch-to-workspace (workspace)
  71. "Prompt for and switch to a WORKSPACE."
  72. (interactive (list (completing-read "Workspace Name: "
  73. (mapcar (lambda (workspace)
  74. (cdr (assoc 'name workspace)))
  75. (i3wm-get-workspaces)))))
  76. (i3wm-workspace workspace))
  77. ;;;###autoload
  78. (defun i3wm-switch-to-workspace-number (number)
  79. "Prompt for and switch to the workspace numbered NUMBER."
  80. (interactive (list (read-number "Workspace Number: ")))
  81. (i3wm-workspace-numbered number))
  82. (provide 'i3wm)
  83. ;;; i3wm.el ends here