i3wm.el 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. (provide 'i3wm)
  45. ;;; i3wm.el ends here