i3wm.el 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. ;; Package-requires: ((cl-lib "0.5") (json))
  6. ;; Keywords: convenience, exteensions
  7. ;; URL: https://git.flintfam.org/swflint/emacs-i3wm
  8. ;;; Commentary:
  9. ;;
  10. ;;; Code:
  11. (require 'json)
  12. (require 'cl-lib)
  13. ;;; Primitive functions:
  14. (defun i3wm-command (command &rest arguments)
  15. "I3wm-command COMMAND &rest ARGUMENTS.
  16. Execute the givenn COMMAND with the given ARGUMENTS."
  17. (json-read-from-string
  18. (shell-command-to-string
  19. (format "i3-msg \"%s\"" (apply #'format command arguments)))))
  20. (defun i3wm-get-workspaces ()
  21. "I3wm-get-workspaces.
  22. List all workspaces."
  23. (json-read-from-string
  24. (shell-command-to-string "i3-msg -t get_workspaces")))
  25. (defun i3wm-get-outputs ()
  26. "I3wm-get-outputs.
  27. List all outputs."
  28. (json-read-from-string
  29. (shell-command-to-string "i3-msg -t get_outputs")))
  30. (defun i3wm-get-version ()
  31. "I3wm-get-version.
  32. Retrieve i3 version."
  33. (json-read-from-string
  34. (shell-command-to-string "i3-msg -t get_version")))
  35. ;;; i3 commands
  36. (defun i3wm-exec (program)
  37. "I3wm-exec PROGRAM.
  38. Executes the given PROGRAM."
  39. (i3wm-command "exec %s" program))
  40. (defun i3wm-exec-no-startup-id (program)
  41. "I3wm-exec-no-startup-id PROGRAM.
  42. Execute the given PROGRAM with --no-startup-id."
  43. (i3wm-command "exec --no-startup-id %s" program))
  44. (defun i3wm-workspace (workspace)
  45. "I3wm-command WORKSPACE.
  46. Switch to the given i3 workspace"
  47. (i3wm-command "workspace %s" workspace))
  48. (defun i3wm-workspace-numbered (number)
  49. "I3wm-workspace-numbered NUMBER.
  50. Switch to the workspace with the given number."
  51. (i3wm-command "workspace number %d" number))
  52. (defun i3wm-workspace-next ()
  53. "I3wm-workspace-next.
  54. Switch to the next workspace."
  55. (i3wm-command "workspace next"))
  56. (defun i3wm-workspace-prev ()
  57. "I3wm-workspace-prev.
  58. Switch to the previous workspace."
  59. (i3wm-command "workspace prev"))
  60. (defun i3wm-split-horizontally ()
  61. "I3wm-split-horizontally.
  62. Split the current container horizontally."
  63. (i3wm-command "split h"))
  64. (defun i3wm-split-vertically ()
  65. "I3wm-split-vertically.
  66. Split the current container vertically."
  67. (i3wm-command "split v"))
  68. (defun i3wm-stacking ()
  69. "I3wm-stacking.
  70. Switch to a stacking layout."
  71. (i3wm-command "layout stacking"))
  72. (defun i3wm-tabbed ()
  73. "I3wm-tabbed.
  74. Switch to a tabbed layout."
  75. (i3wm-command "layout tabbed"))
  76. (defun i3wm-fullscreen ()
  77. "I3wm-fullscreen.
  78. Switch to a fullscreen layout."
  79. (i3wm-command "fullscreen toggle"))
  80. (defun i3wm-floating ()
  81. "I3wm-floating.
  82. Toggle container floating."
  83. (i3wm-command "floating toggle"))
  84. (provide 'i3wm)
  85. ;;; i3wm.el ends here