mirror of
				https://github.com/DreamMaoMao/maomaowm.git
				synced 2025-11-03 09:01:47 -05:00 
			
		
		
		
	format code
This commit is contained in:
		
							parent
							
								
									b3ccf3b8b8
								
							
						
					
					
						commit
						7e66d5390e
					
				
					 8 changed files with 1085 additions and 1174 deletions
				
			
		| 
						 | 
				
			
			@ -6,18 +6,14 @@
 | 
			
		|||
 */
 | 
			
		||||
 | 
			
		||||
/* Leave these functions first; they're used in the others */
 | 
			
		||||
static inline int
 | 
			
		||||
client_is_x11(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline int client_is_x11(Client *c) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  return c->type == X11;
 | 
			
		||||
#endif
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline struct wlr_surface *
 | 
			
		||||
client_surface(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline struct wlr_surface *client_surface(Client *c) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c))
 | 
			
		||||
    return c->surface.xwayland->surface;
 | 
			
		||||
| 
						 | 
				
			
			@ -25,9 +21,8 @@ client_surface(Client *c)
 | 
			
		|||
  return c->surface.xdg->surface;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int
 | 
			
		||||
toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
 | 
			
		||||
{
 | 
			
		||||
static inline int toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc,
 | 
			
		||||
                                            LayerSurface **pl) {
 | 
			
		||||
  struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface;
 | 
			
		||||
  struct wlr_surface *root_surface;
 | 
			
		||||
  struct wlr_layer_surface_v1 *layer_surface;
 | 
			
		||||
| 
						 | 
				
			
			@ -50,7 +45,8 @@ toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
 | 
			
		|||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
	if ((layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
 | 
			
		||||
  if ((layer_surface =
 | 
			
		||||
           wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
 | 
			
		||||
    l = layer_surface->data;
 | 
			
		||||
    type = LayerShell;
 | 
			
		||||
    goto end;
 | 
			
		||||
| 
						 | 
				
			
			@ -64,7 +60,8 @@ toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc, LayerSurface **pl)
 | 
			
		|||
      if (!xdg_surface->popup || !xdg_surface->popup->parent)
 | 
			
		||||
        return -1;
 | 
			
		||||
 | 
			
		||||
			tmp_xdg_surface = wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent);
 | 
			
		||||
      tmp_xdg_surface =
 | 
			
		||||
          wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent);
 | 
			
		||||
 | 
			
		||||
      if (!tmp_xdg_surface)
 | 
			
		||||
        return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl);
 | 
			
		||||
| 
						 | 
				
			
			@ -89,9 +86,8 @@ end:
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/* The others */
 | 
			
		||||
static inline void
 | 
			
		||||
client_activate_surface(struct wlr_surface *s, int activated)
 | 
			
		||||
{
 | 
			
		||||
static inline void client_activate_surface(struct wlr_surface *s,
 | 
			
		||||
                                           int activated) {
 | 
			
		||||
  struct wlr_xdg_toplevel *toplevel;
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  struct wlr_xwayland_surface *xsurface;
 | 
			
		||||
| 
						 | 
				
			
			@ -104,16 +100,16 @@ client_activate_surface(struct wlr_surface *s, int activated)
 | 
			
		|||
    wlr_xdg_toplevel_set_activated(toplevel, activated);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline uint32_t
 | 
			
		||||
client_set_bounds(Client *c, int32_t width, int32_t height)
 | 
			
		||||
{
 | 
			
		||||
static inline uint32_t client_set_bounds(Client *c, int32_t width,
 | 
			
		||||
                                         int32_t height) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c))
 | 
			
		||||
    return 0;
 | 
			
		||||
#endif
 | 
			
		||||
  if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
 | 
			
		||||
			XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION && width >= 0 && height >= 0
 | 
			
		||||
			&& (c->bounds.width != width || c->bounds.height != height)) {
 | 
			
		||||
          XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION &&
 | 
			
		||||
      width >= 0 && height >= 0 &&
 | 
			
		||||
      (c->bounds.width != width || c->bounds.height != height)) {
 | 
			
		||||
    c->bounds.width = width;
 | 
			
		||||
    c->bounds.height = height;
 | 
			
		||||
    return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height);
 | 
			
		||||
| 
						 | 
				
			
			@ -121,19 +117,16 @@ client_set_bounds(Client *c, int32_t width, int32_t height)
 | 
			
		|||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline const char *
 | 
			
		||||
client_get_appid(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline const char *client_get_appid(Client *c) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c))
 | 
			
		||||
    return c->surface.xwayland->class ? c->surface.xwayland->class : "broken";
 | 
			
		||||
#endif
 | 
			
		||||
	return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id : "broken";
 | 
			
		||||
  return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id
 | 
			
		||||
                                          : "broken";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int
 | 
			
		||||
client_get_pid(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline int client_get_pid(Client *c) {
 | 
			
		||||
  pid_t pid;
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c))
 | 
			
		||||
| 
						 | 
				
			
			@ -143,9 +136,7 @@ client_get_pid(Client *c)
 | 
			
		|||
  return pid;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
client_get_clip(Client *c, struct wlr_box *clip)
 | 
			
		||||
{
 | 
			
		||||
static inline void client_get_clip(Client *c, struct wlr_box *clip) {
 | 
			
		||||
  *clip = (struct wlr_box){
 | 
			
		||||
      .x = 0,
 | 
			
		||||
      .y = 0,
 | 
			
		||||
| 
						 | 
				
			
			@ -162,9 +153,7 @@ client_get_clip(Client *c, struct wlr_box *clip)
 | 
			
		|||
  clip->y = c->surface.xdg->geometry.y;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
client_get_geometry(Client *c, struct wlr_box *geom)
 | 
			
		||||
{
 | 
			
		||||
static inline void client_get_geometry(Client *c, struct wlr_box *geom) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c)) {
 | 
			
		||||
    geom->x = c->surface.xwayland->x;
 | 
			
		||||
| 
						 | 
				
			
			@ -177,9 +166,7 @@ client_get_geometry(Client *c, struct wlr_box *geom)
 | 
			
		|||
  *geom = c->surface.xdg->geometry;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline Client *
 | 
			
		||||
client_get_parent(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline Client *client_get_parent(Client *c) {
 | 
			
		||||
  Client *p = NULL;
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c)) {
 | 
			
		||||
| 
						 | 
				
			
			@ -189,13 +176,12 @@ client_get_parent(Client *c)
 | 
			
		|||
  }
 | 
			
		||||
#endif
 | 
			
		||||
  if (c->surface.xdg->toplevel->parent)
 | 
			
		||||
		toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface, &p, NULL);
 | 
			
		||||
    toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface,
 | 
			
		||||
                              &p, NULL);
 | 
			
		||||
  return p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int
 | 
			
		||||
client_has_children(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline int client_has_children(Client *c) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c))
 | 
			
		||||
    return !wl_list_empty(&c->surface.xwayland->children);
 | 
			
		||||
| 
						 | 
				
			
			@ -205,19 +191,16 @@ client_has_children(Client *c)
 | 
			
		|||
  return wl_list_length(&c->surface.xdg->link) > 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline const char *
 | 
			
		||||
client_get_title(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline const char *client_get_title(Client *c) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c))
 | 
			
		||||
    return c->surface.xwayland->title ? c->surface.xwayland->title : "broken";
 | 
			
		||||
#endif
 | 
			
		||||
	return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title : "broken";
 | 
			
		||||
  return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title
 | 
			
		||||
                                         : "broken";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int
 | 
			
		||||
client_is_float_type(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline int client_is_float_type(Client *c) {
 | 
			
		||||
  struct wlr_xdg_toplevel *toplevel;
 | 
			
		||||
  struct wlr_xdg_toplevel_state state;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -228,29 +211,32 @@ client_is_float_type(Client *c)
 | 
			
		|||
    if (surface->modal)
 | 
			
		||||
      return 1;
 | 
			
		||||
 | 
			
		||||
		if (wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG)
 | 
			
		||||
				|| wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH)
 | 
			
		||||
				|| wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR)
 | 
			
		||||
				|| wlr_xwayland_surface_has_window_type(surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) {
 | 
			
		||||
    if (wlr_xwayland_surface_has_window_type(
 | 
			
		||||
            surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG) ||
 | 
			
		||||
        wlr_xwayland_surface_has_window_type(
 | 
			
		||||
            surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH) ||
 | 
			
		||||
        wlr_xwayland_surface_has_window_type(
 | 
			
		||||
            surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR) ||
 | 
			
		||||
        wlr_xwayland_surface_has_window_type(
 | 
			
		||||
            surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) {
 | 
			
		||||
      return 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
		return size_hints && size_hints->min_width > 0 && size_hints->min_height > 0
 | 
			
		||||
			&& (size_hints->max_width == size_hints->min_width
 | 
			
		||||
				|| size_hints->max_height == size_hints->min_height);
 | 
			
		||||
    return size_hints && size_hints->min_width > 0 &&
 | 
			
		||||
           size_hints->min_height > 0 &&
 | 
			
		||||
           (size_hints->max_width == size_hints->min_width ||
 | 
			
		||||
            size_hints->max_height == size_hints->min_height);
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
  toplevel = c->surface.xdg->toplevel;
 | 
			
		||||
  state = toplevel->current;
 | 
			
		||||
	return toplevel->parent || (state.min_width != 0 && state.min_height != 0
 | 
			
		||||
		&& (state.min_width == state.max_width
 | 
			
		||||
			|| state.min_height == state.max_height));
 | 
			
		||||
  return toplevel->parent || (state.min_width != 0 && state.min_height != 0 &&
 | 
			
		||||
                              (state.min_width == state.max_width ||
 | 
			
		||||
                               state.min_height == state.max_height));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int
 | 
			
		||||
client_is_rendered_on_mon(Client *c, Monitor *m)
 | 
			
		||||
{
 | 
			
		||||
static inline int client_is_rendered_on_mon(Client *c, Monitor *m) {
 | 
			
		||||
  /* This is needed for when you don't want to check formal assignment,
 | 
			
		||||
   * but rather actual displaying of the pixels.
 | 
			
		||||
   * Usually VISIBLEON suffices and is also faster. */
 | 
			
		||||
| 
						 | 
				
			
			@ -258,15 +244,12 @@ client_is_rendered_on_mon(Client *c, Monitor *m)
 | 
			
		|||
  int unused_lx, unused_ly;
 | 
			
		||||
  if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly))
 | 
			
		||||
    return 0;
 | 
			
		||||
	wl_list_for_each(s, &client_surface(c)->current_outputs, link)
 | 
			
		||||
		if (s->output == m->wlr_output)
 | 
			
		||||
			return 1;
 | 
			
		||||
  wl_list_for_each(s, &client_surface(c)->current_outputs,
 | 
			
		||||
                   link) if (s->output == m->wlr_output) return 1;
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int
 | 
			
		||||
client_is_stopped(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline int client_is_stopped(Client *c) {
 | 
			
		||||
  int pid;
 | 
			
		||||
  siginfo_t in = {0};
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
| 
						 | 
				
			
			@ -275,7 +258,7 @@ client_is_stopped(Client *c)
 | 
			
		|||
#endif
 | 
			
		||||
 | 
			
		||||
  wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
 | 
			
		||||
	if (waitid(P_PID, pid, &in, WNOHANG|WCONTINUED|WSTOPPED|WNOWAIT) < 0) {
 | 
			
		||||
  if (waitid(P_PID, pid, &in, WNOHANG | WCONTINUED | WSTOPPED | WNOWAIT) < 0) {
 | 
			
		||||
    /* This process is not our child process, while is very unluckely that
 | 
			
		||||
     * it is stopped, in order to do not skip frames assume that it is. */
 | 
			
		||||
    if (errno == ECHILD)
 | 
			
		||||
| 
						 | 
				
			
			@ -290,9 +273,7 @@ client_is_stopped(Client *c)
 | 
			
		|||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int
 | 
			
		||||
client_is_unmanaged(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline int client_is_unmanaged(Client *c) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c))
 | 
			
		||||
    return c->surface.xwayland->override_redirect;
 | 
			
		||||
| 
						 | 
				
			
			@ -300,19 +281,16 @@ client_is_unmanaged(Client *c)
 | 
			
		|||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb)
 | 
			
		||||
{
 | 
			
		||||
static inline void client_notify_enter(struct wlr_surface *s,
 | 
			
		||||
                                       struct wlr_keyboard *kb) {
 | 
			
		||||
  if (kb)
 | 
			
		||||
		wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes,
 | 
			
		||||
				kb->num_keycodes, &kb->modifiers);
 | 
			
		||||
    wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, kb->num_keycodes,
 | 
			
		||||
                                   &kb->modifiers);
 | 
			
		||||
  else
 | 
			
		||||
    wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
client_send_close(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline void client_send_close(Client *c) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c)) {
 | 
			
		||||
    wlr_xwayland_surface_close(c->surface.xwayland);
 | 
			
		||||
| 
						 | 
				
			
			@ -322,17 +300,14 @@ client_send_close(Client *c)
 | 
			
		|||
  wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
client_set_border_color(Client *c, const float color[static 4])
 | 
			
		||||
{
 | 
			
		||||
static inline void client_set_border_color(Client *c,
 | 
			
		||||
                                           const float color[static 4]) {
 | 
			
		||||
  int i;
 | 
			
		||||
  for (i = 0; i < 4; i++)
 | 
			
		||||
    wlr_scene_rect_set_color(c->border[i], color);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
client_set_fullscreen(Client *c, int fullscreen)
 | 
			
		||||
{
 | 
			
		||||
static inline void client_set_fullscreen(Client *c, int fullscreen) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c)) {
 | 
			
		||||
    wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen);
 | 
			
		||||
| 
						 | 
				
			
			@ -342,49 +317,44 @@ client_set_fullscreen(Client *c, int fullscreen)
 | 
			
		|||
  wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
client_set_scale(struct wlr_surface *s, float scale)
 | 
			
		||||
{
 | 
			
		||||
static inline void client_set_scale(struct wlr_surface *s, float scale) {
 | 
			
		||||
  wlr_fractional_scale_v1_notify_scale(s, scale);
 | 
			
		||||
  wlr_surface_set_preferred_buffer_scale(s, (int32_t)ceilf(scale));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline uint32_t
 | 
			
		||||
client_set_size(Client *c, uint32_t width, uint32_t height)
 | 
			
		||||
{
 | 
			
		||||
static inline uint32_t client_set_size(Client *c, uint32_t width,
 | 
			
		||||
                                       uint32_t height) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c)) {
 | 
			
		||||
		wlr_xwayland_surface_configure(c->surface.xwayland,
 | 
			
		||||
				c->geom.x + c->bw, c->geom.y + c->bw, width, height);
 | 
			
		||||
    wlr_xwayland_surface_configure(c->surface.xwayland, c->geom.x + c->bw,
 | 
			
		||||
                                   c->geom.y + c->bw, width, height);
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
	if ((int32_t)width == c->surface.xdg->toplevel->current.width
 | 
			
		||||
			&& (int32_t)height == c->surface.xdg->toplevel->current.height)
 | 
			
		||||
  if ((int32_t)width == c->surface.xdg->toplevel->current.width &&
 | 
			
		||||
      (int32_t)height == c->surface.xdg->toplevel->current.height)
 | 
			
		||||
    return 0;
 | 
			
		||||
	return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width, (int32_t)height);
 | 
			
		||||
  return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width,
 | 
			
		||||
                                   (int32_t)height);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
client_set_tiled(Client *c, uint32_t edges)
 | 
			
		||||
{
 | 
			
		||||
static inline void client_set_tiled(Client *c, uint32_t edges) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c)) {
 | 
			
		||||
		wlr_xwayland_surface_set_maximized(c->surface.xwayland,
 | 
			
		||||
				edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE);
 | 
			
		||||
    wlr_xwayland_surface_set_maximized(
 | 
			
		||||
        c->surface.xwayland, edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
	if (wl_resource_get_version(c->surface.xdg->toplevel->resource)
 | 
			
		||||
			>= XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
 | 
			
		||||
  if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
 | 
			
		||||
      XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
 | 
			
		||||
    wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
 | 
			
		||||
  }
 | 
			
		||||
	wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel, edges != WLR_EDGE_NONE);
 | 
			
		||||
  wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel,
 | 
			
		||||
                                 edges != WLR_EDGE_NONE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void
 | 
			
		||||
client_set_suspended(Client *c, int suspended)
 | 
			
		||||
{
 | 
			
		||||
static inline void client_set_suspended(Client *c, int suspended) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c))
 | 
			
		||||
    return;
 | 
			
		||||
| 
						 | 
				
			
			@ -393,20 +363,18 @@ client_set_suspended(Client *c, int suspended)
 | 
			
		|||
  wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int
 | 
			
		||||
client_wants_focus(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline int client_wants_focus(Client *c) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
	return client_is_unmanaged(c)
 | 
			
		||||
		&& wlr_xwayland_surface_override_redirect_wants_focus(c->surface.xwayland)
 | 
			
		||||
		&& wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) != WLR_ICCCM_INPUT_MODEL_NONE;
 | 
			
		||||
  return client_is_unmanaged(c) &&
 | 
			
		||||
         wlr_xwayland_surface_override_redirect_wants_focus(
 | 
			
		||||
             c->surface.xwayland) &&
 | 
			
		||||
         wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) !=
 | 
			
		||||
             WLR_ICCCM_INPUT_MODEL_NONE;
 | 
			
		||||
#endif
 | 
			
		||||
  return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline int
 | 
			
		||||
client_wants_fullscreen(Client *c)
 | 
			
		||||
{
 | 
			
		||||
static inline int client_wants_fullscreen(Client *c) {
 | 
			
		||||
#ifdef XWAYLAND
 | 
			
		||||
  if (client_is_x11(c))
 | 
			
		||||
    return c->surface.xwayland->fullscreen;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,23 +1,19 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0-only
 | 
			
		||||
/* Based on labwc (https://github.com/labwc/labwc) */
 | 
			
		||||
#define _POSIX_C_SOURCE 200809L
 | 
			
		||||
#include "mem.h"
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "mem.h"
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
die_if_null(void *ptr)
 | 
			
		||||
{
 | 
			
		||||
static void die_if_null(void *ptr) {
 | 
			
		||||
  if (!ptr) {
 | 
			
		||||
    perror("Failed to allocate memory");
 | 
			
		||||
    exit(EXIT_FAILURE);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *
 | 
			
		||||
xzalloc(size_t size)
 | 
			
		||||
{
 | 
			
		||||
void *xzalloc(size_t size) {
 | 
			
		||||
  if (!size) {
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -26,9 +22,7 @@ xzalloc(size_t size)
 | 
			
		|||
  return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *
 | 
			
		||||
xrealloc(void *ptr, size_t size)
 | 
			
		||||
{
 | 
			
		||||
void *xrealloc(void *ptr, size_t size) {
 | 
			
		||||
  if (!size) {
 | 
			
		||||
    free(ptr);
 | 
			
		||||
    return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -38,9 +32,7 @@ xrealloc(void *ptr, size_t size)
 | 
			
		|||
  return ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
char *
 | 
			
		||||
xstrdup(const char *str)
 | 
			
		||||
{
 | 
			
		||||
char *xstrdup(const char *str) {
 | 
			
		||||
  assert(str);
 | 
			
		||||
  char *copy = strdup(str);
 | 
			
		||||
  die_if_null(copy);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,16 +49,20 @@ char *xstrdup(const char *str);
 | 
			
		|||
 * Same as ptr = xstrdup(str) but free
 | 
			
		||||
 * <ptr> before assigning the result.
 | 
			
		||||
 */
 | 
			
		||||
#define xstrdup_replace(ptr, str) do { \
 | 
			
		||||
	free(ptr); (ptr) = xstrdup(str); \
 | 
			
		||||
} while (0)
 | 
			
		||||
#define xstrdup_replace(ptr, str)                                              \
 | 
			
		||||
  do {                                                                         \
 | 
			
		||||
    free(ptr);                                                                 \
 | 
			
		||||
    (ptr) = xstrdup(str);                                                      \
 | 
			
		||||
  } while (0)
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Frees memory pointed to by <ptr> and sets <ptr> to NULL.
 | 
			
		||||
 * Does nothing if <ptr> is already NULL.
 | 
			
		||||
 */
 | 
			
		||||
#define zfree(ptr) do { \
 | 
			
		||||
	free(ptr); (ptr) = NULL; \
 | 
			
		||||
} while (0)
 | 
			
		||||
#define zfree(ptr)                                                             \
 | 
			
		||||
  do {                                                                         \
 | 
			
		||||
    free(ptr);                                                                 \
 | 
			
		||||
    (ptr) = NULL;                                                              \
 | 
			
		||||
  } while (0)
 | 
			
		||||
 | 
			
		||||
#endif /* LABWC_MEM_H */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,21 +1,20 @@
 | 
			
		|||
/* See LICENSE.dwm file for copyright and license details. */
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
 | 
			
		||||
#include "util.h"
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
die(const char *fmt, ...) {
 | 
			
		||||
void die(const char *fmt, ...) {
 | 
			
		||||
  va_list ap;
 | 
			
		||||
 | 
			
		||||
  va_start(ap, fmt);
 | 
			
		||||
  vfprintf(stderr, fmt, ap);
 | 
			
		||||
  va_end(ap);
 | 
			
		||||
 | 
			
		||||
	if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
 | 
			
		||||
  if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
 | 
			
		||||
    fputc(' ', stderr);
 | 
			
		||||
    perror(NULL);
 | 
			
		||||
  } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -25,9 +24,7 @@ die(const char *fmt, ...) {
 | 
			
		|||
  exit(1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *
 | 
			
		||||
ecalloc(size_t nmemb, size_t size)
 | 
			
		||||
{
 | 
			
		||||
void *ecalloc(size_t nmemb, size_t size) {
 | 
			
		||||
  void *p;
 | 
			
		||||
 | 
			
		||||
  if (!(p = calloc(nmemb, size)))
 | 
			
		||||
| 
						 | 
				
			
			@ -35,8 +32,7 @@ ecalloc(size_t nmemb, size_t size)
 | 
			
		|||
  return p;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
fd_set_nonblock(int fd) {
 | 
			
		||||
int fd_set_nonblock(int fd) {
 | 
			
		||||
  int flags = fcntl(fd, F_GETFL);
 | 
			
		||||
  if (flags < 0) {
 | 
			
		||||
    perror("fcntl(F_GETFL):");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -261,17 +261,28 @@ xkb_keysym_t normalize_keysym(xkb_keysym_t sym) {
 | 
			
		|||
 | 
			
		||||
  // 将数字小键盘键转换为普通数字键
 | 
			
		||||
  switch (sym) {
 | 
			
		||||
      case XKB_KEY_KP_0: return XKB_KEY_0;
 | 
			
		||||
      case XKB_KEY_KP_1: return XKB_KEY_1;
 | 
			
		||||
      case XKB_KEY_KP_2: return XKB_KEY_2;
 | 
			
		||||
      case XKB_KEY_KP_3: return XKB_KEY_3;
 | 
			
		||||
      case XKB_KEY_KP_4: return XKB_KEY_4;
 | 
			
		||||
      case XKB_KEY_KP_5: return XKB_KEY_5;
 | 
			
		||||
      case XKB_KEY_KP_6: return XKB_KEY_6;
 | 
			
		||||
      case XKB_KEY_KP_7: return XKB_KEY_7;
 | 
			
		||||
      case XKB_KEY_KP_8: return XKB_KEY_8;
 | 
			
		||||
      case XKB_KEY_KP_9: return XKB_KEY_9;
 | 
			
		||||
      default: return sym;
 | 
			
		||||
  case XKB_KEY_KP_0:
 | 
			
		||||
    return XKB_KEY_0;
 | 
			
		||||
  case XKB_KEY_KP_1:
 | 
			
		||||
    return XKB_KEY_1;
 | 
			
		||||
  case XKB_KEY_KP_2:
 | 
			
		||||
    return XKB_KEY_2;
 | 
			
		||||
  case XKB_KEY_KP_3:
 | 
			
		||||
    return XKB_KEY_3;
 | 
			
		||||
  case XKB_KEY_KP_4:
 | 
			
		||||
    return XKB_KEY_4;
 | 
			
		||||
  case XKB_KEY_KP_5:
 | 
			
		||||
    return XKB_KEY_5;
 | 
			
		||||
  case XKB_KEY_KP_6:
 | 
			
		||||
    return XKB_KEY_6;
 | 
			
		||||
  case XKB_KEY_KP_7:
 | 
			
		||||
    return XKB_KEY_7;
 | 
			
		||||
  case XKB_KEY_KP_8:
 | 
			
		||||
    return XKB_KEY_8;
 | 
			
		||||
  case XKB_KEY_KP_9:
 | 
			
		||||
    return XKB_KEY_9;
 | 
			
		||||
  default:
 | 
			
		||||
    return sym;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -469,7 +480,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value) {
 | 
			
		|||
    func = spawn;
 | 
			
		||||
    (*arg).v = strdup(arg_value);
 | 
			
		||||
  } else if (strcmp(func_name, "spawn_on_empty") == 0) {
 | 
			
		||||
    char cmd[256],tag_num[256];
 | 
			
		||||
    char cmd[256], tag_num[256];
 | 
			
		||||
    if (sscanf(arg_value, "%255[^,],%255s", cmd, tag_num) == 2) {
 | 
			
		||||
      func = spawn_on_empty;
 | 
			
		||||
      (*arg).v = strdup(cmd); // 注意:之后需要释放这个内存
 | 
			
		||||
| 
						 | 
				
			
			@ -524,9 +535,11 @@ void parse_config_line(Config *config, const char *line) {
 | 
			
		|||
  if (strcmp(key, "animations") == 0) {
 | 
			
		||||
    config->animations = atoi(value);
 | 
			
		||||
  } else if (strcmp(key, "animation_type_open") == 0) {
 | 
			
		||||
    snprintf(config->animation_type_open, sizeof(config->animation_type_open), "%.9s", value); // string limit to 9 char
 | 
			
		||||
    snprintf(config->animation_type_open, sizeof(config->animation_type_open),
 | 
			
		||||
             "%.9s", value); // string limit to 9 char
 | 
			
		||||
  } else if (strcmp(key, "animation_type_close") == 0) {
 | 
			
		||||
    snprintf(config->animation_type_close, sizeof(config->animation_type_close), "%.9s", value); // string limit to 9 char
 | 
			
		||||
    snprintf(config->animation_type_close, sizeof(config->animation_type_close),
 | 
			
		||||
             "%.9s", value); // string limit to 9 char
 | 
			
		||||
  } else if (strcmp(key, "animation_fade_in") == 0) {
 | 
			
		||||
    config->animation_fade_in = atoi(value);
 | 
			
		||||
  } else if (strcmp(key, "tag_animation_direction") == 0) {
 | 
			
		||||
| 
						 | 
				
			
			@ -569,9 +582,11 @@ void parse_config_line(Config *config, const char *line) {
 | 
			
		|||
    }
 | 
			
		||||
  } else if (strcmp(key, "animation_curve_close") == 0) {
 | 
			
		||||
    if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_close[0],
 | 
			
		||||
               &config->animation_curve_close[1], &config->animation_curve_close[2],
 | 
			
		||||
               &config->animation_curve_close[1],
 | 
			
		||||
               &config->animation_curve_close[2],
 | 
			
		||||
               &config->animation_curve_close[3]) != 4) {
 | 
			
		||||
      fprintf(stderr, "Error: Invalid animation_curve_close format: %s\n", value);
 | 
			
		||||
      fprintf(stderr, "Error: Invalid animation_curve_close format: %s\n",
 | 
			
		||||
              value);
 | 
			
		||||
    }
 | 
			
		||||
  } else if (strcmp(key, "scroller_structs") == 0) {
 | 
			
		||||
    config->scroller_structs = atoi(value);
 | 
			
		||||
| 
						 | 
				
			
			@ -1041,16 +1056,19 @@ void parse_config_line(Config *config, const char *line) {
 | 
			
		|||
        realloc(config->gesture_bindings,
 | 
			
		||||
                (config->gesture_bindings_count + 1) * sizeof(GestureBinding));
 | 
			
		||||
    if (!config->gesture_bindings) {
 | 
			
		||||
      fprintf(stderr, "Error: Failed to allocate memory for axis gesturebind\n");
 | 
			
		||||
      fprintf(stderr,
 | 
			
		||||
              "Error: Failed to allocate memory for axis gesturebind\n");
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    GestureBinding *binding = &config->gesture_bindings[config->gesture_bindings_count];
 | 
			
		||||
    GestureBinding *binding =
 | 
			
		||||
        &config->gesture_bindings[config->gesture_bindings_count];
 | 
			
		||||
    memset(binding, 0, sizeof(GestureBinding));
 | 
			
		||||
 | 
			
		||||
    char mod_str[256], motion_str[256], fingers_count_str[256] , func_name[256], arg_value[256] = "none";
 | 
			
		||||
    if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str, motion_str, fingers_count_str, func_name,
 | 
			
		||||
               arg_value) < 4) {
 | 
			
		||||
    char mod_str[256], motion_str[256], fingers_count_str[256], func_name[256],
 | 
			
		||||
        arg_value[256] = "none";
 | 
			
		||||
    if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str, motion_str,
 | 
			
		||||
               fingers_count_str, func_name, arg_value) < 4) {
 | 
			
		||||
      fprintf(stderr, "Error: Invalid gesturebind format: %s\n", value);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1195,7 +1213,8 @@ void override_config(void) {
 | 
			
		|||
 | 
			
		||||
  scroller_structs = config.scroller_structs;
 | 
			
		||||
  scroller_default_proportion = config.scroller_default_proportion;
 | 
			
		||||
  scroller_default_proportion_single = config.scroller_default_proportion_single;
 | 
			
		||||
  scroller_default_proportion_single =
 | 
			
		||||
      config.scroller_default_proportion_single;
 | 
			
		||||
  scroller_focus_center = config.scroller_focus_center;
 | 
			
		||||
  focus_cross_monitor = config.focus_cross_monitor;
 | 
			
		||||
  focus_cross_tag = config.focus_cross_tag;
 | 
			
		||||
| 
						 | 
				
			
			@ -1251,16 +1270,22 @@ void set_value_default() {
 | 
			
		|||
  config.animation_fade_in = animation_fade_in; // Enable animation fade in
 | 
			
		||||
  config.tag_animation_direction = tag_animation_direction; // 标签动画方向
 | 
			
		||||
  config.zoom_initial_ratio = zoom_initial_ratio;           // 动画起始窗口比例
 | 
			
		||||
  config.fadein_begin_opacity = fadein_begin_opacity; // Begin opac window ratio for animations
 | 
			
		||||
  config.fadein_begin_opacity =
 | 
			
		||||
      fadein_begin_opacity; // Begin opac window ratio for animations
 | 
			
		||||
  config.fadeout_begin_opacity = fadeout_begin_opacity;
 | 
			
		||||
  config.animation_duration_move = animation_duration_move;  // Animation move speed
 | 
			
		||||
  config.animation_duration_open = animation_duration_open;  // Animation open speed
 | 
			
		||||
  config.animation_duration_move =
 | 
			
		||||
      animation_duration_move; // Animation move speed
 | 
			
		||||
  config.animation_duration_open =
 | 
			
		||||
      animation_duration_open; // Animation open speed
 | 
			
		||||
  config.animation_duration_tag = animation_duration_tag; // Animation tag speed
 | 
			
		||||
  config.animation_duration_close = animation_duration_close; // Animation tag speed
 | 
			
		||||
  config.animation_duration_close =
 | 
			
		||||
      animation_duration_close; // Animation tag speed
 | 
			
		||||
 | 
			
		||||
  /* appearance */
 | 
			
		||||
  config.axis_bind_apply_timeout = axis_bind_apply_timeout; // 滚轮绑定动作的触发的时间间隔
 | 
			
		||||
  config.focus_on_activate = focus_on_activate;         // 收到窗口激活请求是否自动跳转聚焦
 | 
			
		||||
  config.axis_bind_apply_timeout =
 | 
			
		||||
      axis_bind_apply_timeout; // 滚轮绑定动作的触发的时间间隔
 | 
			
		||||
  config.focus_on_activate =
 | 
			
		||||
      focus_on_activate;                    // 收到窗口激活请求是否自动跳转聚焦
 | 
			
		||||
  config.new_is_master = new_is_master;     // 新窗口是否插在头部
 | 
			
		||||
  config.default_mfact = default_mfact;     // master 窗口比例
 | 
			
		||||
  config.default_smfact = default_smfact;   // 第一个stack比例
 | 
			
		||||
| 
						 | 
				
			
			@ -1271,7 +1296,8 @@ void set_value_default() {
 | 
			
		|||
  config.ov_tab_mode = ov_tab_mode;       // alt tab切换模式
 | 
			
		||||
  config.hotarea_size = hotarea_size;     // 热区大小,10x10
 | 
			
		||||
  config.enable_hotarea = enable_hotarea; // 是否启用鼠标热区
 | 
			
		||||
  config.smartgaps = smartgaps; /* 1 means no outer gap when there is only one window */
 | 
			
		||||
  config.smartgaps =
 | 
			
		||||
      smartgaps; /* 1 means no outer gap when there is only one window */
 | 
			
		||||
  config.sloppyfocus = sloppyfocus; /* focus follows mouse */
 | 
			
		||||
  config.gappih = gappih;           /* horiz inner gap between windows */
 | 
			
		||||
  config.gappiv = gappiv;           /* vert inner gap between windows */
 | 
			
		||||
| 
						 | 
				
			
			@ -1280,14 +1306,18 @@ void set_value_default() {
 | 
			
		|||
 | 
			
		||||
  config.scroller_structs = scroller_structs;
 | 
			
		||||
  config.scroller_default_proportion = scroller_default_proportion;
 | 
			
		||||
  config.scroller_default_proportion_single = scroller_default_proportion_single;
 | 
			
		||||
  config.scroller_default_proportion_single =
 | 
			
		||||
      scroller_default_proportion_single;
 | 
			
		||||
  config.scroller_focus_center = scroller_focus_center;
 | 
			
		||||
  config.scroller_prefer_center = scroller_prefer_center;
 | 
			
		||||
  config.focus_cross_monitor = focus_cross_monitor;
 | 
			
		||||
  config.focus_cross_tag = focus_cross_tag;
 | 
			
		||||
  config.swipe_min_threshold = swipe_min_threshold;
 | 
			
		||||
 | 
			
		||||
  config.bypass_surface_visibility = bypass_surface_visibility; /* 1 means idle inhibitors will disable idle tracking even if it's surface isn't visible  */
 | 
			
		||||
  config.bypass_surface_visibility =
 | 
			
		||||
      bypass_surface_visibility; /* 1 means idle inhibitors will disable idle
 | 
			
		||||
                                    tracking even if it's surface isn't visible
 | 
			
		||||
                                  */
 | 
			
		||||
 | 
			
		||||
  config.borderpx = borderpx;
 | 
			
		||||
  config.overviewgappi = overviewgappi; /* overview时 窗口与边缘 缝隙大小 */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -54,7 +54,6 @@ int focus_cross_tag = 0;
 | 
			
		|||
 | 
			
		||||
unsigned int swipe_min_threshold = 20;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int bypass_surface_visibility =
 | 
			
		||||
    0; /* 1 means idle inhibitors will disable idle tracking even if it's
 | 
			
		||||
          surface isn't visible  */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										39
									
								
								src/maomao.c
									
										
									
									
									
								
							
							
						
						
									
										39
									
								
								src/maomao.c
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -78,8 +78,8 @@
 | 
			
		|||
#include <xcb/xcb_icccm.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "dwl-ipc-unstable-v2-protocol.h"
 | 
			
		||||
#include "common/util.h"
 | 
			
		||||
#include "dwl-ipc-unstable-v2-protocol.h"
 | 
			
		||||
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
 | 
			
		||||
 | 
			
		||||
/* macros */
 | 
			
		||||
| 
						 | 
				
			
			@ -109,7 +109,7 @@
 | 
			
		|||
#define BAKED_POINTS_COUNT 256
 | 
			
		||||
 | 
			
		||||
/* enums */
 | 
			
		||||
enum { VERTICAL, HORIZONTAL};
 | 
			
		||||
enum { VERTICAL, HORIZONTAL };
 | 
			
		||||
enum { SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT };
 | 
			
		||||
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
 | 
			
		||||
enum { XDGShell, LayerShell, X11 };                 /* client types */
 | 
			
		||||
| 
						 | 
				
			
			@ -1561,7 +1561,8 @@ applyrulesgeom(Client *c) {
 | 
			
		|||
    r = &config.window_rules[ji];
 | 
			
		||||
    if ((r->title && strstr(title, r->title) && !r->id) ||
 | 
			
		||||
        (r->id && strstr(appid, r->id) && !r->title) ||
 | 
			
		||||
        (r->id && strstr(appid, r->id) && r->title && strstr(title, r->title))) {
 | 
			
		||||
        (r->id && strstr(appid, r->id) && r->title &&
 | 
			
		||||
         strstr(title, r->title))) {
 | 
			
		||||
      c->geom.width = r->width > 0 ? r->width : c->geom.width;
 | 
			
		||||
      c->geom.height = r->height > 0 ? r->height : c->geom.height;
 | 
			
		||||
      // 重新计算居中的坐标
 | 
			
		||||
| 
						 | 
				
			
			@ -1598,7 +1599,8 @@ applyrules(Client *c) {
 | 
			
		|||
 | 
			
		||||
    if ((r->title && strstr(title, r->title) && !r->id) ||
 | 
			
		||||
        (r->id && strstr(appid, r->id) && !r->title) ||
 | 
			
		||||
        (r->id && strstr(appid, r->id) && r->title && strstr(title, r->title))) {
 | 
			
		||||
        (r->id && strstr(appid, r->id) && r->title &&
 | 
			
		||||
         strstr(title, r->title))) {
 | 
			
		||||
      c->isterm = r->isterm > 0 ? r->isterm : c->isterm;
 | 
			
		||||
      c->noswallow = r->noswallow > 0 ? r->noswallow : c->noswallow;
 | 
			
		||||
      c->isfloating = r->isfloating > 0 ? r->isfloating : c->isfloating;
 | 
			
		||||
| 
						 | 
				
			
			@ -1691,11 +1693,9 @@ arrange(Monitor *m, bool want_animation) {
 | 
			
		|||
          wlr_scene_node_set_enabled(&c->scene->node, true);
 | 
			
		||||
        }
 | 
			
		||||
        client_set_suspended(c, false);
 | 
			
		||||
        if (!c->animation.from_rule && 
 | 
			
		||||
            want_animation &&
 | 
			
		||||
            m->pertag->prevtag != 0 && 
 | 
			
		||||
            m->pertag->curtag != 0 && 
 | 
			
		||||
            animations && !c->animation.running) {
 | 
			
		||||
        if (!c->animation.from_rule && want_animation &&
 | 
			
		||||
            m->pertag->prevtag != 0 && m->pertag->curtag != 0 && animations &&
 | 
			
		||||
            !c->animation.running) {
 | 
			
		||||
          c->animation.tagining = true;
 | 
			
		||||
          if (m->pertag->curtag > m->pertag->prevtag) {
 | 
			
		||||
            c->animainit_geom.x = tag_animation_direction == VERTICAL
 | 
			
		||||
| 
						 | 
				
			
			@ -1725,8 +1725,7 @@ arrange(Monitor *m, bool want_animation) {
 | 
			
		|||
 | 
			
		||||
      } else {
 | 
			
		||||
        if ((c->tags & (1 << (selmon->pertag->prevtag - 1))) &&
 | 
			
		||||
            m->pertag->prevtag != 0 &&
 | 
			
		||||
            m->pertag->curtag != 0 && animations) {
 | 
			
		||||
            m->pertag->prevtag != 0 && m->pertag->curtag != 0 && animations) {
 | 
			
		||||
          c->animation.tagouting = true;
 | 
			
		||||
          c->animation.tagining = false;
 | 
			
		||||
          if (m->pertag->curtag > m->pertag->prevtag) {
 | 
			
		||||
| 
						 | 
				
			
			@ -2302,7 +2301,7 @@ buttonpress(struct wl_listener *listener, void *data) {
 | 
			
		|||
      wlr_seat_pointer_clear_focus(seat);
 | 
			
		||||
      motionnotify(0, NULL, 0, 0, 0, 0);
 | 
			
		||||
      /* Drop the window off on its new monitor */
 | 
			
		||||
      if(grabc == selmon->sel){
 | 
			
		||||
      if (grabc == selmon->sel) {
 | 
			
		||||
        selmon->sel = NULL;
 | 
			
		||||
      }
 | 
			
		||||
      selmon = xytomon(cursor->x, cursor->y);
 | 
			
		||||
| 
						 | 
				
			
			@ -2590,7 +2589,8 @@ void client_commit(Client *c) {
 | 
			
		|||
void commitnotify(struct wl_listener *listener, void *data) {
 | 
			
		||||
  Client *c = wl_container_of(listener, c, commit);
 | 
			
		||||
 | 
			
		||||
  if(!c->surface.xdg->initialized) return;
 | 
			
		||||
  if (!c->surface.xdg->initialized)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  if (c->surface.xdg->initial_commit) {
 | 
			
		||||
    // xdg client will first enter this before mapnotify
 | 
			
		||||
| 
						 | 
				
			
			@ -2620,7 +2620,8 @@ void commitnotify(struct wl_listener *listener, void *data) {
 | 
			
		|||
    return;
 | 
			
		||||
 | 
			
		||||
  uint32_t serial = c->surface.xdg->current.configure_serial;
 | 
			
		||||
  if(!c->dirty || serial < c->configure_serial) return;
 | 
			
		||||
  if (!c->dirty || serial < c->configure_serial)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  struct wlr_box geometry;
 | 
			
		||||
  client_get_geometry(c, &geometry);
 | 
			
		||||
| 
						 | 
				
			
			@ -3729,7 +3730,8 @@ bool keypressglobal(struct wlr_surface *last_surface,
 | 
			
		|||
 | 
			
		||||
          if ((r->title && strstr(title, r->title) && !r->id) ||
 | 
			
		||||
              (r->id && strstr(appid, r->id) && !r->title) ||
 | 
			
		||||
          (r->id && strstr(appid, r->id) && r->title && strstr(title, r->title))) {
 | 
			
		||||
              (r->id && strstr(appid, r->id) && r->title &&
 | 
			
		||||
               strstr(title, r->title))) {
 | 
			
		||||
            reset = true;
 | 
			
		||||
            wlr_seat_keyboard_enter(seat, client_surface(c), keycodes, 0,
 | 
			
		||||
                                    &keyboard->modifiers);
 | 
			
		||||
| 
						 | 
				
			
			@ -4798,7 +4800,8 @@ void resize(Client *c, struct wlr_box geo, int interact) {
 | 
			
		|||
  bbox = interact ? &sgeom : &c->mon->w;
 | 
			
		||||
 | 
			
		||||
  if (strcmp(c->mon->pertag->ltidxs[c->mon->pertag->curtag]->name,
 | 
			
		||||
             "scroller") == 0 && !c->isfloating) {
 | 
			
		||||
             "scroller") == 0 &&
 | 
			
		||||
      !c->isfloating) {
 | 
			
		||||
    c->geom = geo;
 | 
			
		||||
    c->geom.width = MAX(1 + 2 * (int)c->bw, c->geom.width);
 | 
			
		||||
    c->geom.height = MAX(1 + 2 * (int)c->bw, c->geom.height);
 | 
			
		||||
| 
						 | 
				
			
			@ -6506,10 +6509,10 @@ void unmapnotify(struct wl_listener *listener, void *data) {
 | 
			
		|||
    if (!m->wlr_output->enabled) {
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
    if(c == m->sel){
 | 
			
		||||
    if (c == m->sel) {
 | 
			
		||||
      m->sel = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    if(c == m->prevsel){
 | 
			
		||||
    if (c == m->prevsel) {
 | 
			
		||||
      m->prevsel = NULL;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,20 +1,19 @@
 | 
			
		|||
// SPDX-License-Identifier: GPL-2.0-only
 | 
			
		||||
/* Based on labwc (https://github.com/labwc/labwc) */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifndef LABWC_IME_H
 | 
			
		||||
#define LABWC_IME_H
 | 
			
		||||
 | 
			
		||||
#include <wlr/types/wlr_text_input_v3.h>
 | 
			
		||||
#include <wlr/types/wlr_input_method_v2.h>
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include "../common/mem.h"
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <wlr/types/wlr_input_method_v2.h>
 | 
			
		||||
#include <wlr/types/wlr_text_input_v3.h>
 | 
			
		||||
 | 
			
		||||
#define LAB_SET_MAX_SIZE 16
 | 
			
		||||
 | 
			
		||||
#define SAME_CLIENT(wlr_obj1, wlr_obj2)                                        \
 | 
			
		||||
	(wl_resource_get_client((wlr_obj1)->resource) \
 | 
			
		||||
	== wl_resource_get_client((wlr_obj2)->resource))
 | 
			
		||||
  (wl_resource_get_client((wlr_obj1)->resource) ==                             \
 | 
			
		||||
   wl_resource_get_client((wlr_obj2)->resource))
 | 
			
		||||
 | 
			
		||||
struct lab_set {
 | 
			
		||||
  uint32_t values[LAB_SET_MAX_SIZE];
 | 
			
		||||
| 
						 | 
				
			
			@ -90,8 +89,8 @@ struct input_method_relay *input_method_relay;
 | 
			
		|||
 * if the keyboard grab exists.
 | 
			
		||||
 * Returns true if the key event was forwarded.
 | 
			
		||||
 */
 | 
			
		||||
bool input_method_keyboard_grab_forward_key(KeyboardGroup *keyboard,
 | 
			
		||||
	struct wlr_keyboard_key_event *event);
 | 
			
		||||
bool input_method_keyboard_grab_forward_key(
 | 
			
		||||
    KeyboardGroup *keyboard, struct wlr_keyboard_key_event *event);
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Forward modifier state to keyboard grab of the seat from the keyboard
 | 
			
		||||
| 
						 | 
				
			
			@ -108,11 +107,7 @@ void input_method_relay_finish(struct input_method_relay *relay);
 | 
			
		|||
void input_method_relay_set_focus(struct input_method_relay *relay,
 | 
			
		||||
                                  struct wlr_surface *surface);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
bool
 | 
			
		||||
lab_set_contains(struct lab_set *set, uint32_t value)
 | 
			
		||||
{
 | 
			
		||||
bool lab_set_contains(struct lab_set *set, uint32_t value) {
 | 
			
		||||
  for (int i = 0; i < set->size; ++i) {
 | 
			
		||||
    if (set->values[i] == value) {
 | 
			
		||||
      return true;
 | 
			
		||||
| 
						 | 
				
			
			@ -121,9 +116,7 @@ lab_set_contains(struct lab_set *set, uint32_t value)
 | 
			
		|||
  return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
lab_set_add(struct lab_set *set, uint32_t value)
 | 
			
		||||
{
 | 
			
		||||
void lab_set_add(struct lab_set *set, uint32_t value) {
 | 
			
		||||
  if (lab_set_contains(set, value)) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -134,9 +127,7 @@ lab_set_add(struct lab_set *set, uint32_t value)
 | 
			
		|||
  set->values[set->size++] = value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
lab_set_remove(struct lab_set *set, uint32_t value)
 | 
			
		||||
{
 | 
			
		||||
void lab_set_remove(struct lab_set *set, uint32_t value) {
 | 
			
		||||
  for (int i = 0; i < set->size; ++i) {
 | 
			
		||||
    if (set->values[i] == value) {
 | 
			
		||||
      --set->size;
 | 
			
		||||
| 
						 | 
				
			
			@ -146,10 +137,7 @@ lab_set_remove(struct lab_set *set, uint32_t value)
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Monitor *
 | 
			
		||||
output_from_wlr_output(struct wlr_output *wlr_output)
 | 
			
		||||
{
 | 
			
		||||
Monitor *output_from_wlr_output(struct wlr_output *wlr_output) {
 | 
			
		||||
  Monitor *m;
 | 
			
		||||
  wl_list_for_each(m, &mons, link) {
 | 
			
		||||
    if (m->wlr_output == wlr_output) {
 | 
			
		||||
| 
						 | 
				
			
			@ -159,30 +147,23 @@ output_from_wlr_output(struct wlr_output *wlr_output)
 | 
			
		|||
  return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Monitor *
 | 
			
		||||
output_nearest_to(int lx, int ly)
 | 
			
		||||
{
 | 
			
		||||
Monitor *output_nearest_to(int lx, int ly) {
 | 
			
		||||
  double closest_x, closest_y;
 | 
			
		||||
	wlr_output_layout_closest_point(output_layout, NULL, lx, ly,
 | 
			
		||||
		&closest_x, &closest_y);
 | 
			
		||||
  wlr_output_layout_closest_point(output_layout, NULL, lx, ly, &closest_x,
 | 
			
		||||
                                  &closest_y);
 | 
			
		||||
 | 
			
		||||
  return output_from_wlr_output(
 | 
			
		||||
		wlr_output_layout_output_at(output_layout,
 | 
			
		||||
			closest_x, closest_y));
 | 
			
		||||
      wlr_output_layout_output_at(output_layout, closest_x, closest_y));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool
 | 
			
		||||
output_is_usable(Monitor *m)
 | 
			
		||||
{
 | 
			
		||||
bool output_is_usable(Monitor *m) {
 | 
			
		||||
  /* output_is_usable(NULL) is safe and returns false */
 | 
			
		||||
  return m && m->wlr_output->enabled;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static bool
 | 
			
		||||
is_keyboard_emulated_by_input_method(struct wlr_keyboard *keyboard,
 | 
			
		||||
		struct wlr_input_method_v2 *input_method)
 | 
			
		||||
{
 | 
			
		||||
                                     struct wlr_input_method_v2 *input_method) {
 | 
			
		||||
  if (!keyboard || !input_method) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -198,16 +179,14 @@ is_keyboard_emulated_by_input_method(struct wlr_keyboard *keyboard,
 | 
			
		|||
 * to it.
 | 
			
		||||
 */
 | 
			
		||||
static struct wlr_input_method_keyboard_grab_v2 *
 | 
			
		||||
get_keyboard_grab(KeyboardGroup *keyboard)
 | 
			
		||||
{
 | 
			
		||||
	struct wlr_input_method_v2 *input_method =
 | 
			
		||||
		input_method_relay->input_method;
 | 
			
		||||
get_keyboard_grab(KeyboardGroup *keyboard) {
 | 
			
		||||
  struct wlr_input_method_v2 *input_method = input_method_relay->input_method;
 | 
			
		||||
  if (!input_method || !input_method->keyboard_grab) {
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // labwc not need this , but maomao need
 | 
			
		||||
	if(keyboard != kb_group)
 | 
			
		||||
  if (keyboard != kb_group)
 | 
			
		||||
    return NULL;
 | 
			
		||||
 | 
			
		||||
  /*
 | 
			
		||||
| 
						 | 
				
			
			@ -217,17 +196,15 @@ get_keyboard_grab(KeyboardGroup *keyboard)
 | 
			
		|||
   * input-method so key events don't loop between the compositor and
 | 
			
		||||
   * the input-method.
 | 
			
		||||
   */
 | 
			
		||||
	if (is_keyboard_emulated_by_input_method(
 | 
			
		||||
			&keyboard->wlr_group->keyboard, input_method)) {
 | 
			
		||||
  if (is_keyboard_emulated_by_input_method(&keyboard->wlr_group->keyboard,
 | 
			
		||||
                                           input_method)) {
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return input_method->keyboard_grab;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool
 | 
			
		||||
input_method_keyboard_grab_forward_modifiers(KeyboardGroup *keyboard)
 | 
			
		||||
{
 | 
			
		||||
bool input_method_keyboard_grab_forward_modifiers(KeyboardGroup *keyboard) {
 | 
			
		||||
  struct wlr_input_method_keyboard_grab_v2 *keyboard_grab =
 | 
			
		||||
      get_keyboard_grab(keyboard);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -236,37 +213,33 @@ input_method_keyboard_grab_forward_modifiers(KeyboardGroup *keyboard)
 | 
			
		|||
  struct wlr_keyboard_modifiers *modifiers =
 | 
			
		||||
      &keyboard->wlr_group->keyboard.modifiers;
 | 
			
		||||
 | 
			
		||||
	if (forwarded_modifiers->depressed == modifiers->depressed
 | 
			
		||||
			&& forwarded_modifiers->latched == modifiers->latched
 | 
			
		||||
			&& forwarded_modifiers->locked == modifiers->locked
 | 
			
		||||
			&& forwarded_modifiers->group == modifiers->group) {
 | 
			
		||||
  if (forwarded_modifiers->depressed == modifiers->depressed &&
 | 
			
		||||
      forwarded_modifiers->latched == modifiers->latched &&
 | 
			
		||||
      forwarded_modifiers->locked == modifiers->locked &&
 | 
			
		||||
      forwarded_modifiers->group == modifiers->group) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if (keyboard_grab) {
 | 
			
		||||
    *forwarded_modifiers = keyboard->wlr_group->keyboard.modifiers;
 | 
			
		||||
		wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab,
 | 
			
		||||
			&keyboard->wlr_group->keyboard);
 | 
			
		||||
		wlr_input_method_keyboard_grab_v2_send_modifiers(keyboard_grab,
 | 
			
		||||
			modifiers);
 | 
			
		||||
    wlr_input_method_keyboard_grab_v2_set_keyboard(
 | 
			
		||||
        keyboard_grab, &keyboard->wlr_group->keyboard);
 | 
			
		||||
    wlr_input_method_keyboard_grab_v2_send_modifiers(keyboard_grab, modifiers);
 | 
			
		||||
    return true;
 | 
			
		||||
  } else {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool
 | 
			
		||||
input_method_keyboard_grab_forward_key(KeyboardGroup *keyboard,
 | 
			
		||||
		struct wlr_keyboard_key_event *event)
 | 
			
		||||
{
 | 
			
		||||
bool input_method_keyboard_grab_forward_key(
 | 
			
		||||
    KeyboardGroup *keyboard, struct wlr_keyboard_key_event *event) {
 | 
			
		||||
  /*
 | 
			
		||||
   * We should not forward key-release events without corresponding
 | 
			
		||||
   * key-press events forwarded
 | 
			
		||||
   */
 | 
			
		||||
	struct lab_set *pressed_keys =
 | 
			
		||||
		&input_method_relay->forwarded_pressed_keys;
 | 
			
		||||
	if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED
 | 
			
		||||
			&& !lab_set_contains(pressed_keys, event->keycode)) {
 | 
			
		||||
  struct lab_set *pressed_keys = &input_method_relay->forwarded_pressed_keys;
 | 
			
		||||
  if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED &&
 | 
			
		||||
      !lab_set_contains(pressed_keys, event->keycode)) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -278,10 +251,10 @@ input_method_keyboard_grab_forward_key(KeyboardGroup *keyboard,
 | 
			
		|||
    } else {
 | 
			
		||||
      lab_set_remove(pressed_keys, event->keycode);
 | 
			
		||||
    }
 | 
			
		||||
		wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab,
 | 
			
		||||
			&keyboard->wlr_group->keyboard);
 | 
			
		||||
		wlr_input_method_keyboard_grab_v2_send_key(keyboard_grab,
 | 
			
		||||
			event->time_msec, event->keycode, event->state);
 | 
			
		||||
    wlr_input_method_keyboard_grab_v2_set_keyboard(
 | 
			
		||||
        keyboard_grab, &keyboard->wlr_group->keyboard);
 | 
			
		||||
    wlr_input_method_keyboard_grab_v2_send_key(keyboard_grab, event->time_msec,
 | 
			
		||||
                                               event->keycode, event->state);
 | 
			
		||||
    return true;
 | 
			
		||||
  } else {
 | 
			
		||||
    return false;
 | 
			
		||||
| 
						 | 
				
			
			@ -293,15 +266,14 @@ input_method_keyboard_grab_forward_key(KeyboardGroup *keyboard,
 | 
			
		|||
 * right text-inputs to choose from.
 | 
			
		||||
 */
 | 
			
		||||
static struct text_input *
 | 
			
		||||
get_active_text_input(struct input_method_relay *relay)
 | 
			
		||||
{
 | 
			
		||||
get_active_text_input(struct input_method_relay *relay) {
 | 
			
		||||
  if (!relay->input_method) {
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
  struct text_input *text_input;
 | 
			
		||||
  wl_list_for_each(text_input, &relay->text_inputs, link) {
 | 
			
		||||
		if (text_input->input->focused_surface
 | 
			
		||||
				&& text_input->input->current_enabled) {
 | 
			
		||||
    if (text_input->input->focused_surface &&
 | 
			
		||||
        text_input->input->current_enabled) {
 | 
			
		||||
      return text_input;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -312,13 +284,10 @@ get_active_text_input(struct input_method_relay *relay)
 | 
			
		|||
 * Updates active text-input and activates/deactivates the input-method if the
 | 
			
		||||
 * value is changed.
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
update_active_text_input(struct input_method_relay *relay)
 | 
			
		||||
{
 | 
			
		||||
static void update_active_text_input(struct input_method_relay *relay) {
 | 
			
		||||
  struct text_input *active_text_input = get_active_text_input(relay);
 | 
			
		||||
 | 
			
		||||
	if (relay->input_method && relay->active_text_input
 | 
			
		||||
			!= active_text_input) {
 | 
			
		||||
  if (relay->input_method && relay->active_text_input != active_text_input) {
 | 
			
		||||
    if (active_text_input) {
 | 
			
		||||
      wlr_input_method_v2_send_activate(relay->input_method);
 | 
			
		||||
    } else {
 | 
			
		||||
| 
						 | 
				
			
			@ -339,15 +308,14 @@ update_active_text_input(struct input_method_relay *relay)
 | 
			
		|||
 * the text-input active and start communicating with input-method.
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
update_text_inputs_focused_surface(struct input_method_relay *relay)
 | 
			
		||||
{
 | 
			
		||||
update_text_inputs_focused_surface(struct input_method_relay *relay) {
 | 
			
		||||
  struct text_input *text_input;
 | 
			
		||||
  wl_list_for_each(text_input, &relay->text_inputs, link) {
 | 
			
		||||
    struct wlr_text_input_v3 *input = text_input->input;
 | 
			
		||||
 | 
			
		||||
    struct wlr_surface *new_focused_surface;
 | 
			
		||||
		if (relay->input_method && relay->focused_surface
 | 
			
		||||
				&& SAME_CLIENT(input, relay->focused_surface)) {
 | 
			
		||||
    if (relay->input_method && relay->focused_surface &&
 | 
			
		||||
        SAME_CLIENT(input, relay->focused_surface)) {
 | 
			
		||||
      new_focused_surface = relay->focused_surface;
 | 
			
		||||
    } else {
 | 
			
		||||
      new_focused_surface = NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -365,14 +333,12 @@ update_text_inputs_focused_surface(struct input_method_relay *relay)
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
update_popup_position(struct input_method_popup *popup)
 | 
			
		||||
{
 | 
			
		||||
static void update_popup_position(struct input_method_popup *popup) {
 | 
			
		||||
  struct input_method_relay *relay = popup->relay;
 | 
			
		||||
  struct text_input *text_input = relay->active_text_input;
 | 
			
		||||
 | 
			
		||||
	if (!text_input || !relay->focused_surface
 | 
			
		||||
			|| !popup->popup_surface->surface->mapped) {
 | 
			
		||||
  if (!text_input || !relay->focused_surface ||
 | 
			
		||||
      !popup->popup_surface->surface->mapped) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -382,9 +348,9 @@ update_popup_position(struct input_method_popup *popup)
 | 
			
		|||
  struct wlr_layer_surface_v1 *layer_surface =
 | 
			
		||||
      wlr_layer_surface_v1_try_from_wlr_surface(relay->focused_surface);
 | 
			
		||||
 | 
			
		||||
	if ((text_input->input->current.features
 | 
			
		||||
			& WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE)
 | 
			
		||||
			&& (xdg_surface || layer_surface)) {
 | 
			
		||||
  if ((text_input->input->current.features &
 | 
			
		||||
       WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE) &&
 | 
			
		||||
      (xdg_surface || layer_surface)) {
 | 
			
		||||
    cursor_rect = text_input->input->current.cursor_rectangle;
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
| 
						 | 
				
			
			@ -408,37 +374,33 @@ update_popup_position(struct input_method_popup *popup)
 | 
			
		|||
    cursor_rect = (struct wlr_box){0};
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
	Monitor *output =
 | 
			
		||||
		output_nearest_to(cursor_rect.x, cursor_rect.y);
 | 
			
		||||
  Monitor *output = output_nearest_to(cursor_rect.x, cursor_rect.y);
 | 
			
		||||
  if (!output_is_usable(output)) {
 | 
			
		||||
		wlr_log(WLR_ERROR,
 | 
			
		||||
			"Cannot position IME popup (unusable output)");
 | 
			
		||||
    wlr_log(WLR_ERROR, "Cannot position IME popup (unusable output)");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  struct wlr_box output_box;
 | 
			
		||||
	wlr_output_layout_get_box(
 | 
			
		||||
		output_layout, output->wlr_output, &output_box);
 | 
			
		||||
  wlr_output_layout_get_box(output_layout, output->wlr_output, &output_box);
 | 
			
		||||
 | 
			
		||||
  /* Use xdg-positioner utilities to position popup */
 | 
			
		||||
  struct wlr_xdg_positioner_rules rules = {
 | 
			
		||||
      .anchor_rect = cursor_rect,
 | 
			
		||||
      .anchor = XDG_POSITIONER_ANCHOR_BOTTOM_LEFT,
 | 
			
		||||
      .gravity = XDG_POSITIONER_GRAVITY_BOTTOM_RIGHT,
 | 
			
		||||
		.size = {
 | 
			
		||||
      .size =
 | 
			
		||||
          {
 | 
			
		||||
              .width = popup->popup_surface->surface->current.width,
 | 
			
		||||
              .height = popup->popup_surface->surface->current.height,
 | 
			
		||||
          },
 | 
			
		||||
		.constraint_adjustment =
 | 
			
		||||
			XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y
 | 
			
		||||
			| XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X,
 | 
			
		||||
      .constraint_adjustment = XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_FLIP_Y |
 | 
			
		||||
                               XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  struct wlr_box popup_box;
 | 
			
		||||
  wlr_xdg_positioner_rules_get_geometry(&rules, &popup_box);
 | 
			
		||||
  wlr_xdg_positioner_rules_unconstrain_box(&rules, &output_box, &popup_box);
 | 
			
		||||
 | 
			
		||||
	wlr_scene_node_set_position(
 | 
			
		||||
		&popup->tree->node, popup_box.x, popup_box.y);
 | 
			
		||||
  wlr_scene_node_set_position(&popup->tree->node, popup_box.x, popup_box.y);
 | 
			
		||||
  /* Make sure IME popups are always on top, above layer-shell surfaces */
 | 
			
		||||
  wlr_scene_node_raise_to_top(&relay->popup_tree->node);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -451,18 +413,15 @@ update_popup_position(struct input_method_popup *popup)
 | 
			
		|||
                            });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
update_popups_position(struct input_method_relay *relay)
 | 
			
		||||
{
 | 
			
		||||
static void update_popups_position(struct input_method_relay *relay) {
 | 
			
		||||
  struct input_method_popup *popup;
 | 
			
		||||
  wl_list_for_each(popup, &relay->popups, link) {
 | 
			
		||||
    update_popup_position(popup);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_input_method_commit(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
static void handle_input_method_commit(struct wl_listener *listener,
 | 
			
		||||
                                       void *data) {
 | 
			
		||||
  struct input_method_relay *relay =
 | 
			
		||||
      wl_container_of(listener, relay, input_method_commit);
 | 
			
		||||
  struct wlr_input_method_v2 *input_method = data;
 | 
			
		||||
| 
						 | 
				
			
			@ -475,29 +434,25 @@ handle_input_method_commit(struct wl_listener *listener, void *data)
 | 
			
		|||
 | 
			
		||||
  if (input_method->current.preedit.text) {
 | 
			
		||||
    wlr_text_input_v3_send_preedit_string(
 | 
			
		||||
			text_input->input,
 | 
			
		||||
			input_method->current.preedit.text,
 | 
			
		||||
        text_input->input, input_method->current.preedit.text,
 | 
			
		||||
        input_method->current.preedit.cursor_begin,
 | 
			
		||||
        input_method->current.preedit.cursor_end);
 | 
			
		||||
  }
 | 
			
		||||
  if (input_method->current.commit_text) {
 | 
			
		||||
		wlr_text_input_v3_send_commit_string(
 | 
			
		||||
			text_input->input,
 | 
			
		||||
    wlr_text_input_v3_send_commit_string(text_input->input,
 | 
			
		||||
                                         input_method->current.commit_text);
 | 
			
		||||
  }
 | 
			
		||||
	if (input_method->current.delete.before_length
 | 
			
		||||
			|| input_method->current.delete.after_length) {
 | 
			
		||||
  if (input_method->current.delete.before_length ||
 | 
			
		||||
      input_method->current.delete.after_length) {
 | 
			
		||||
    wlr_text_input_v3_send_delete_surrounding_text(
 | 
			
		||||
			text_input->input,
 | 
			
		||||
			input_method->current.delete.before_length,
 | 
			
		||||
        text_input->input, input_method->current.delete.before_length,
 | 
			
		||||
        input_method->current.delete.after_length);
 | 
			
		||||
  }
 | 
			
		||||
  wlr_text_input_v3_send_done(text_input->input);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_keyboard_grab_destroy(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
static void handle_keyboard_grab_destroy(struct wl_listener *listener,
 | 
			
		||||
                                         void *data) {
 | 
			
		||||
  struct input_method_relay *relay =
 | 
			
		||||
      wl_container_of(listener, relay, keyboard_grab_destroy);
 | 
			
		||||
  struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data;
 | 
			
		||||
| 
						 | 
				
			
			@ -505,40 +460,35 @@ handle_keyboard_grab_destroy(struct wl_listener *listener, void *data)
 | 
			
		|||
 | 
			
		||||
  if (keyboard_grab->keyboard) {
 | 
			
		||||
    /* Send modifier state to original client */
 | 
			
		||||
		wlr_seat_keyboard_notify_modifiers(
 | 
			
		||||
			keyboard_grab->input_method->seat,
 | 
			
		||||
    wlr_seat_keyboard_notify_modifiers(keyboard_grab->input_method->seat,
 | 
			
		||||
                                       &keyboard_grab->keyboard->modifiers);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_input_method_grab_keyboard(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct input_method_relay *relay = wl_container_of(listener, relay,
 | 
			
		||||
		input_method_grab_keyboard);
 | 
			
		||||
static void handle_input_method_grab_keyboard(struct wl_listener *listener,
 | 
			
		||||
                                              void *data) {
 | 
			
		||||
  struct input_method_relay *relay =
 | 
			
		||||
      wl_container_of(listener, relay, input_method_grab_keyboard);
 | 
			
		||||
  struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data;
 | 
			
		||||
 | 
			
		||||
	struct wlr_keyboard *active_keyboard =
 | 
			
		||||
		wlr_seat_get_keyboard(seat);
 | 
			
		||||
  struct wlr_keyboard *active_keyboard = wlr_seat_get_keyboard(seat);
 | 
			
		||||
 | 
			
		||||
	if (!is_keyboard_emulated_by_input_method(
 | 
			
		||||
			active_keyboard, relay->input_method)) {
 | 
			
		||||
  if (!is_keyboard_emulated_by_input_method(active_keyboard,
 | 
			
		||||
                                            relay->input_method)) {
 | 
			
		||||
    /* Send modifier state to grab */
 | 
			
		||||
		wlr_input_method_keyboard_grab_v2_set_keyboard(
 | 
			
		||||
			keyboard_grab, active_keyboard);
 | 
			
		||||
    wlr_input_method_keyboard_grab_v2_set_keyboard(keyboard_grab,
 | 
			
		||||
                                                   active_keyboard);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  relay->forwarded_pressed_keys = (struct lab_set){0};
 | 
			
		||||
  relay->forwarded_modifiers = (struct wlr_keyboard_modifiers){0};
 | 
			
		||||
 | 
			
		||||
  relay->keyboard_grab_destroy.notify = handle_keyboard_grab_destroy;
 | 
			
		||||
	wl_signal_add(&keyboard_grab->events.destroy,
 | 
			
		||||
		&relay->keyboard_grab_destroy);
 | 
			
		||||
  wl_signal_add(&keyboard_grab->events.destroy, &relay->keyboard_grab_destroy);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_input_method_destroy(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
static void handle_input_method_destroy(struct wl_listener *listener,
 | 
			
		||||
                                        void *data) {
 | 
			
		||||
  struct input_method_relay *relay =
 | 
			
		||||
      wl_container_of(listener, relay, input_method_destroy);
 | 
			
		||||
  assert(relay->input_method == data);
 | 
			
		||||
| 
						 | 
				
			
			@ -552,11 +502,9 @@ handle_input_method_destroy(struct wl_listener *listener, void *data)
 | 
			
		|||
  update_active_text_input(relay);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_popup_surface_destroy(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct input_method_popup *popup =
 | 
			
		||||
		wl_container_of(listener, popup, destroy);
 | 
			
		||||
static void handle_popup_surface_destroy(struct wl_listener *listener,
 | 
			
		||||
                                         void *data) {
 | 
			
		||||
  struct input_method_popup *popup = wl_container_of(listener, popup, destroy);
 | 
			
		||||
  wlr_scene_node_destroy(&popup->tree->node);
 | 
			
		||||
  wl_list_remove(&popup->destroy.link);
 | 
			
		||||
  wl_list_remove(&popup->commit.link);
 | 
			
		||||
| 
						 | 
				
			
			@ -564,19 +512,16 @@ handle_popup_surface_destroy(struct wl_listener *listener, void *data)
 | 
			
		|||
  free(popup);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_popup_surface_commit(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct input_method_popup *popup =
 | 
			
		||||
		wl_container_of(listener, popup, commit);
 | 
			
		||||
static void handle_popup_surface_commit(struct wl_listener *listener,
 | 
			
		||||
                                        void *data) {
 | 
			
		||||
  struct input_method_popup *popup = wl_container_of(listener, popup, commit);
 | 
			
		||||
  update_popup_position(popup);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_input_method_new_popup_surface(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct input_method_relay *relay = wl_container_of(listener, relay,
 | 
			
		||||
		input_method_new_popup_surface);
 | 
			
		||||
static void handle_input_method_new_popup_surface(struct wl_listener *listener,
 | 
			
		||||
                                                  void *data) {
 | 
			
		||||
  struct input_method_relay *relay =
 | 
			
		||||
      wl_container_of(listener, relay, input_method_new_popup_surface);
 | 
			
		||||
 | 
			
		||||
  struct input_method_popup *popup = znew(*popup);
 | 
			
		||||
  popup->popup_surface = data;
 | 
			
		||||
| 
						 | 
				
			
			@ -586,17 +531,18 @@ handle_input_method_new_popup_surface(struct wl_listener *listener, void *data)
 | 
			
		|||
  wl_signal_add(&popup->popup_surface->events.destroy, &popup->destroy);
 | 
			
		||||
 | 
			
		||||
  popup->commit.notify = handle_popup_surface_commit;
 | 
			
		||||
	wl_signal_add(&popup->popup_surface->surface->events.commit,
 | 
			
		||||
		&popup->commit);
 | 
			
		||||
  wl_signal_add(&popup->popup_surface->surface->events.commit, &popup->commit);
 | 
			
		||||
 | 
			
		||||
  // popup->tree = wlr_scene_subsurface_tree_create(
 | 
			
		||||
  // 	relay->popup_tree, popup->popup_surface->surface);
 | 
			
		||||
  // node_descriptor_create(&popup->tree->node, LAB_NODE_DESC_IME_POPUP, NULL);
 | 
			
		||||
 | 
			
		||||
  popup->tree = wlr_scene_tree_create(layers[LyrIMPopup]);
 | 
			
		||||
	popup->scene_surface = wlr_scene_subsurface_tree_create(popup->tree,popup->popup_surface->surface);
 | 
			
		||||
	//popup->scene_surface = &wlr_scene_subsurface_tree_create(popup->scene->parent,popup->popup_surface->surface)->node;
 | 
			
		||||
	//popup->scene_surface->data = popup;
 | 
			
		||||
  popup->scene_surface = wlr_scene_subsurface_tree_create(
 | 
			
		||||
      popup->tree, popup->popup_surface->surface);
 | 
			
		||||
  // popup->scene_surface =
 | 
			
		||||
  // &wlr_scene_subsurface_tree_create(popup->scene->parent,popup->popup_surface->surface)->node;
 | 
			
		||||
  // popup->scene_surface->data = popup;
 | 
			
		||||
  popup->scene_surface->node.data = popup;
 | 
			
		||||
 | 
			
		||||
  wl_list_insert(&relay->popups, &popup->link);
 | 
			
		||||
| 
						 | 
				
			
			@ -604,9 +550,7 @@ handle_input_method_new_popup_surface(struct wl_listener *listener, void *data)
 | 
			
		|||
  update_popup_position(popup);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_new_input_method(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
static void handle_new_input_method(struct wl_listener *listener, void *data) {
 | 
			
		||||
  struct input_method_relay *relay =
 | 
			
		||||
      wl_container_of(listener, relay, new_input_method);
 | 
			
		||||
  struct wlr_input_method_v2 *input_method = data;
 | 
			
		||||
| 
						 | 
				
			
			@ -615,8 +559,7 @@ handle_new_input_method(struct wl_listener *listener, void *data)
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  if (relay->input_method) {
 | 
			
		||||
		wlr_log(WLR_INFO,
 | 
			
		||||
			"Attempted to connect second input method to a seat");
 | 
			
		||||
    wlr_log(WLR_INFO, "Attempted to connect second input method to a seat");
 | 
			
		||||
    wlr_input_method_v2_send_unavailable(input_method);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -627,8 +570,7 @@ handle_new_input_method(struct wl_listener *listener, void *data)
 | 
			
		|||
  wl_signal_add(&relay->input_method->events.commit,
 | 
			
		||||
                &relay->input_method_commit);
 | 
			
		||||
 | 
			
		||||
	relay->input_method_grab_keyboard.notify =
 | 
			
		||||
		handle_input_method_grab_keyboard;
 | 
			
		||||
  relay->input_method_grab_keyboard.notify = handle_input_method_grab_keyboard;
 | 
			
		||||
  wl_signal_add(&relay->input_method->events.grab_keyboard,
 | 
			
		||||
                &relay->input_method_grab_keyboard);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -646,21 +588,17 @@ handle_new_input_method(struct wl_listener *listener, void *data)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
/* Conveys state from active text-input to input-method */
 | 
			
		||||
static void
 | 
			
		||||
send_state_to_input_method(struct input_method_relay *relay)
 | 
			
		||||
{
 | 
			
		||||
static void send_state_to_input_method(struct input_method_relay *relay) {
 | 
			
		||||
  assert(relay->active_text_input && relay->input_method);
 | 
			
		||||
 | 
			
		||||
  struct wlr_input_method_v2 *input_method = relay->input_method;
 | 
			
		||||
  struct wlr_text_input_v3 *input = relay->active_text_input->input;
 | 
			
		||||
 | 
			
		||||
  /* TODO: only send each of those if they were modified */
 | 
			
		||||
	if (input->active_features
 | 
			
		||||
			& WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT) {
 | 
			
		||||
		wlr_input_method_v2_send_surrounding_text(input_method,
 | 
			
		||||
			input->current.surrounding.text,
 | 
			
		||||
			input->current.surrounding.cursor,
 | 
			
		||||
			input->current.surrounding.anchor);
 | 
			
		||||
  if (input->active_features & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT) {
 | 
			
		||||
    wlr_input_method_v2_send_surrounding_text(
 | 
			
		||||
        input_method, input->current.surrounding.text,
 | 
			
		||||
        input->current.surrounding.cursor, input->current.surrounding.anchor);
 | 
			
		||||
  }
 | 
			
		||||
  wlr_input_method_v2_send_text_change_cause(input_method,
 | 
			
		||||
                                             input->current.text_change_cause);
 | 
			
		||||
| 
						 | 
				
			
			@ -672,11 +610,8 @@ send_state_to_input_method(struct input_method_relay *relay)
 | 
			
		|||
  wlr_input_method_v2_send_done(input_method);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_text_input_enable(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct text_input *text_input =
 | 
			
		||||
		wl_container_of(listener, text_input, enable);
 | 
			
		||||
static void handle_text_input_enable(struct wl_listener *listener, void *data) {
 | 
			
		||||
  struct text_input *text_input = wl_container_of(listener, text_input, enable);
 | 
			
		||||
  struct input_method_relay *relay = text_input->relay;
 | 
			
		||||
 | 
			
		||||
  update_active_text_input(relay);
 | 
			
		||||
| 
						 | 
				
			
			@ -686,9 +621,8 @@ handle_text_input_enable(struct wl_listener *listener, void *data)
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_text_input_disable(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
static void handle_text_input_disable(struct wl_listener *listener,
 | 
			
		||||
                                      void *data) {
 | 
			
		||||
  struct text_input *text_input =
 | 
			
		||||
      wl_container_of(listener, text_input, disable);
 | 
			
		||||
  /*
 | 
			
		||||
| 
						 | 
				
			
			@ -699,11 +633,8 @@ handle_text_input_disable(struct wl_listener *listener, void *data)
 | 
			
		|||
  update_active_text_input(text_input->relay);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_text_input_commit(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct text_input *text_input =
 | 
			
		||||
		wl_container_of(listener, text_input, commit);
 | 
			
		||||
static void handle_text_input_commit(struct wl_listener *listener, void *data) {
 | 
			
		||||
  struct text_input *text_input = wl_container_of(listener, text_input, commit);
 | 
			
		||||
  struct input_method_relay *relay = text_input->relay;
 | 
			
		||||
 | 
			
		||||
  if (relay->active_text_input == text_input) {
 | 
			
		||||
| 
						 | 
				
			
			@ -712,9 +643,8 @@ handle_text_input_commit(struct wl_listener *listener, void *data)
 | 
			
		|||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_text_input_destroy(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
static void handle_text_input_destroy(struct wl_listener *listener,
 | 
			
		||||
                                      void *data) {
 | 
			
		||||
  struct text_input *text_input =
 | 
			
		||||
      wl_container_of(listener, text_input, destroy);
 | 
			
		||||
  wl_list_remove(&text_input->enable.link);
 | 
			
		||||
| 
						 | 
				
			
			@ -726,9 +656,7 @@ handle_text_input_destroy(struct wl_listener *listener, void *data)
 | 
			
		|||
  free(text_input);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void
 | 
			
		||||
handle_new_text_input(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
static void handle_new_text_input(struct wl_listener *listener, void *data) {
 | 
			
		||||
  struct input_method_relay *relay =
 | 
			
		||||
      wl_container_of(listener, relay, new_text_input);
 | 
			
		||||
  struct wlr_text_input_v3 *wlr_text_input = data;
 | 
			
		||||
| 
						 | 
				
			
			@ -761,9 +689,8 @@ handle_new_text_input(struct wl_listener *listener, void *data)
 | 
			
		|||
 * role (like xdg_toplevel) first and input_method_relay_set_focus() is called
 | 
			
		||||
 * before wl_surface is destroyed.
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
handle_focused_surface_destroy(struct wl_listener *listener, void *data)
 | 
			
		||||
{
 | 
			
		||||
static void handle_focused_surface_destroy(struct wl_listener *listener,
 | 
			
		||||
                                           void *data) {
 | 
			
		||||
  struct input_method_relay *relay =
 | 
			
		||||
      wl_container_of(listener, relay, focused_surface_destroy);
 | 
			
		||||
  assert(relay->focused_surface == data);
 | 
			
		||||
| 
						 | 
				
			
			@ -771,17 +698,14 @@ handle_focused_surface_destroy(struct wl_listener *listener, void *data)
 | 
			
		|||
  input_method_relay_set_focus(relay, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct input_method_relay *
 | 
			
		||||
input_method_relay_create()
 | 
			
		||||
{
 | 
			
		||||
struct input_method_relay *input_method_relay_create() {
 | 
			
		||||
  struct input_method_relay *relay = znew(*relay);
 | 
			
		||||
  wl_list_init(&relay->text_inputs);
 | 
			
		||||
  wl_list_init(&relay->popups);
 | 
			
		||||
  relay->popup_tree = wlr_scene_tree_create(&scene->tree);
 | 
			
		||||
 | 
			
		||||
  relay->new_text_input.notify = handle_new_text_input;
 | 
			
		||||
	wl_signal_add(&text_input_manager->events.text_input,
 | 
			
		||||
		&relay->new_text_input);
 | 
			
		||||
  wl_signal_add(&text_input_manager->events.text_input, &relay->new_text_input);
 | 
			
		||||
 | 
			
		||||
  relay->new_input_method.notify = handle_new_input_method;
 | 
			
		||||
  wl_signal_add(&input_method_manager->events.input_method,
 | 
			
		||||
| 
						 | 
				
			
			@ -792,18 +716,14 @@ input_method_relay_create()
 | 
			
		|||
  return relay;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
input_method_relay_finish(struct input_method_relay *relay)
 | 
			
		||||
{
 | 
			
		||||
void input_method_relay_finish(struct input_method_relay *relay) {
 | 
			
		||||
  wl_list_remove(&relay->new_text_input.link);
 | 
			
		||||
  wl_list_remove(&relay->new_input_method.link);
 | 
			
		||||
  free(relay);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
input_method_relay_set_focus(struct input_method_relay *relay,
 | 
			
		||||
		struct wlr_surface *surface)
 | 
			
		||||
{
 | 
			
		||||
void input_method_relay_set_focus(struct input_method_relay *relay,
 | 
			
		||||
                                  struct wlr_surface *surface) {
 | 
			
		||||
  if (relay->focused_surface == surface) {
 | 
			
		||||
    wlr_log(WLR_INFO, "The surface is already focused");
 | 
			
		||||
    return;
 | 
			
		||||
| 
						 | 
				
			
			@ -814,8 +734,7 @@ input_method_relay_set_focus(struct input_method_relay *relay,
 | 
			
		|||
  }
 | 
			
		||||
  relay->focused_surface = surface;
 | 
			
		||||
  if (surface) {
 | 
			
		||||
		wl_signal_add(&surface->events.destroy,
 | 
			
		||||
			&relay->focused_surface_destroy);
 | 
			
		||||
    wl_signal_add(&surface->events.destroy, &relay->focused_surface_destroy);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  update_text_inputs_focused_surface(relay);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue