logo

inaban

Distrustful Wayland Compositor (inspired by XMonad and dwm) git clone https://hacktivis.me/git/inaban.git

commands.c (2165B)


  1. // SPDX-FileCopyrightText: 2019-2022 inaban Authors <https://hacktivis.me/git/inaban>
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "inaban.h"
  4. #include <stdlib.h>
  5. #include <unistd.h> /* fork(), execvp() */
  6. // defined in inaban.c
  7. extern struct inaban_server server;
  8. void
  9. spawn(const Arg *arg)
  10. {
  11. if(fork() == 0)
  12. {
  13. setsid();
  14. execvp(((char **)arg->v)[0], (char **)arg->v);
  15. fprintf(stderr, "execvp %s", ((char **)arg->v)[0]);
  16. perror(" failed");
  17. exit(EXIT_SUCCESS);
  18. }
  19. }
  20. /* Note: this function only deals with keyboard focus. */
  21. void
  22. focus_view(struct inaban_view *view, struct wlr_surface *surface)
  23. {
  24. if(view == NULL) return;
  25. struct inaban_server *server = view->server;
  26. struct wlr_seat *seat = server->seat;
  27. struct wlr_surface *prev_surface = seat->keyboard_state.focused_surface;
  28. if(prev_surface == surface) return; /* Don't re-focus an already focused surface. */
  29. if(prev_surface)
  30. {
  31. /*
  32. * Deactivate the previously focused surface. This lets the client know
  33. * it no longer has focus and the client will repaint accordingly, e.g.
  34. * stop displaying a caret.
  35. */
  36. struct wlr_xdg_surface *previous =
  37. wlr_xdg_surface_from_wlr_surface(seat->keyboard_state.focused_surface);
  38. wlr_xdg_toplevel_set_activated(previous, false);
  39. }
  40. struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat);
  41. /* Move the view to the front */
  42. wl_list_remove(&view->link);
  43. wl_list_insert(&server->views, &view->link);
  44. /* Activate the new surface */
  45. wlr_xdg_toplevel_set_activated(view->xdg_surface, true);
  46. /*
  47. * Tell the seat to have the keyboard enter this surface. wlroots will keep
  48. * track of this and automatically send key events to the appropriate
  49. * clients without additional work on your part.
  50. */
  51. wlr_seat_keyboard_notify_enter(seat,
  52. view->xdg_surface->surface,
  53. keyboard->keycodes,
  54. keyboard->num_keycodes,
  55. &keyboard->modifiers);
  56. }
  57. void
  58. quit(const Arg *arg)
  59. {
  60. (void)arg;
  61. wl_display_terminate(server.wl_display);
  62. }
  63. void
  64. lock(const Arg *arg)
  65. {
  66. (void)arg;
  67. server.locked = true;
  68. }