Add xdg-system-bell-v1 support

aae8cac69a1163b158edcedc2a4fe34a5d68bda6
Alexis Sellier committed ago 1 parent 488f4e61
swm.c +32 -9
71 71
#include <wlr/types/wlr_xdg_activation_v1.h>
72 72
#include <wlr/types/wlr_xdg_decoration_v1.h>
73 73
#include <wlr/types/wlr_xdg_dialog_v1.h>
74 74
#include <wlr/types/wlr_xdg_output_v1.h>
75 75
#include <wlr/types/wlr_xdg_shell.h>
76 +
#include <wlr/types/wlr_xdg_system_bell_v1.h>
76 77
#include <wlr/util/log.h>
77 78
#include <wlr/util/region.h>
78 79
#include <wlr/xwayland.h>
79 80
#include <xcb/xcb.h>
80 81
#include <xcb/xcb_icccm.h>
590 591
static void       unmap_notify(struct wl_listener *listener, void *data);
591 592
static void       update_monitors(struct wl_listener *listener, void *data);
592 593
static void       update_app_id(struct wl_listener *listener, void *data);
593 594
static void       update_title(struct wl_listener *listener, void *data);
594 595
static void       urgent(struct wl_listener *listener, void *data);
596 +
static void       ring_system_bell(struct wl_listener *listener, void *data);
597 +
static void       mark_urgent(client_t *c);
595 598
static void       create_dialog(struct wl_listener *listener, void *data);
596 599
static void       dialog_changed(struct wl_listener *listener, void *data);
597 600
static void       dialog_destroyed(struct wl_listener *listener, void *data);
598 601
static void       view(const arg_t *arg);
599 602
static void       virtual_keyboard(struct wl_listener *listener, void *data);
630 633
static struct wlr_compositor *compositor;
631 634
static struct wlr_session    *session;
632 635
633 636
static struct wlr_xdg_shell                             *xdg_shell;
634 637
static struct wlr_xdg_wm_dialog_v1                      *xdg_dialog_mgr;
638 +
static struct wlr_xdg_system_bell_v1                    *system_bell;
635 639
static struct wlr_xdg_activation_v1                     *activation;
636 640
static struct wlr_xdg_decoration_manager_v1             *xdg_decoration_mgr;
637 641
static struct wl_list                                    clients; /* tiling order */
638 642
static struct wl_list                                    fstack;  /* focus order */
639 643
static struct wlr_idle_notifier_v1                      *idle_notifier;
713 717
static struct wl_listener new_layer_surface                = { .notify = create_layer_surface };
714 718
static struct wl_listener output_mgr_apply                 = { .notify = output_manager_apply };
715 719
static struct wl_listener output_mgr_test                  = { .notify = output_manager_test };
716 720
static struct wl_listener output_power_mgr_set_mode        = { .notify = power_manager_set_mode };
717 721
static struct wl_listener request_activate                 = { .notify = urgent };
722 +
static struct wl_listener system_bell_ring                 = { .notify = ring_system_bell };
718 723
static struct wl_listener request_cursor                   = { .notify = set_cursor };
719 724
static struct wl_listener request_set_psel                 = { .notify = set_primary_selection };
720 725
static struct wl_listener request_set_sel                  = { .notify = set_selection };
721 726
static struct wl_listener request_set_cursor_shape         = { .notify = set_cursor_shape };
722 727
static struct wl_listener request_start_drag_listener      = { .notify = request_start_drag };
890 895
        return -1;
891 896
    root_surface = wlr_surface_get_root_surface(s);
892 897
893 898
    if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(root_surface))) {
894 899
        c    = xsurface->data;
895 -
        type = c->type;
900 +
        type = c ? (int)c->type : -1;
896 901
        goto end;
897 902
    }
898 903
    if ((layer_surface = wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
899 904
        l    = layer_surface->data;
900 -
        type = LAYER_SHELL;
905 +
        type = l ? LAYER_SHELL : -1;
901 906
        goto end;
902 907
    }
903 908
    xdg_surface = wlr_xdg_surface_try_from_wlr_surface(root_surface);
904 909
905 910
    while (xdg_surface) {
918 923
919 924
            xdg_surface = tmp_xdg_surface;
920 925
            break;
921 926
        case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
922 927
            c    = xdg_surface->data;
923 -
            type = c->type;
928 +
            type = c ? (int)c->type : -1;
924 929
            goto end;
925 930
        case WLR_XDG_SURFACE_ROLE_NONE:
926 931
            return -1;
927 932
        }
928 933
    }
2005 2010
    wl_list_remove(&ext_ftl_capture_request.link);
2006 2011
    wl_list_remove(&output_mgr_apply.link);
2007 2012
    wl_list_remove(&output_mgr_test.link);
2008 2013
    wl_list_remove(&output_power_mgr_set_mode.link);
2009 2014
    wl_list_remove(&request_activate.link);
2015 +
    wl_list_remove(&system_bell_ring.link);
2010 2016
    wl_list_remove(&request_cursor.link);
2011 2017
    wl_list_remove(&request_set_psel.link);
2012 2018
    wl_list_remove(&request_set_sel.link);
2013 2019
    wl_list_remove(&request_set_cursor_shape.link);
2014 2020
    wl_list_remove(&request_start_drag_listener.link);
5291 5297
5292 5298
    /* Accept application requests for attention. */
5293 5299
    activation = wlr_xdg_activation_v1_create(dpy);
5294 5300
    wl_signal_add(&activation->events.request_activate, &request_activate);
5295 5301
5302 +
    system_bell = wlr_xdg_system_bell_v1_create(dpy, 1);
5303 +
    wl_signal_add(&system_bell->events.ring, &system_bell_ring);
5304 +
5296 5305
    wlr_scene_set_gamma_control_manager_v1(scene, wlr_gamma_control_manager_v1_create(dpy));
5297 5306
5298 5307
    power_mgr = wlr_output_power_manager_v1_create(dpy);
5299 5308
    wl_signal_add(&power_mgr->events.set_mode, &output_power_mgr_set_mode);
5300 5309
5873 5882
5874 5883
    if (c == focus_top(c->mon))
5875 5884
        print_status();
5876 5885
}
5877 5886
5878 -
/* Mark an unfocused window as needing attention. */
5879 -
void urgent(struct wl_listener *listener, void *data) {
5880 -
    struct wlr_xdg_activation_v1_request_activate_event *event = data;
5881 -
    client_t                                            *c     = nullptr;
5882 -
    toplevel_from_wlr_surface(event->surface, &c, nullptr);
5883 -
5887 +
/* Mark an unfocused managed window as needing attention. */
5888 +
void mark_urgent(client_t *c) {
5884 5889
    if (!c || c == focus_top(selmon))
5885 5890
        return;
5886 5891
5887 5892
    c->is_urgent = true;
5888 5893
    print_status();
5889 5894
5890 5895
    if (client_surface(c)->mapped)
5891 5896
        client_set_border_color(c, urgentcolor);
5892 5897
}
5893 5898
5899 +
/* Handle an activation request as an urgency notification. */
5900 +
void urgent(struct wl_listener *listener, void *data) {
5901 +
    struct wlr_xdg_activation_v1_request_activate_event *event = data;
5902 +
    client_t                                            *c     = nullptr;
5903 +
5904 +
    toplevel_from_wlr_surface(event->surface, &c, nullptr);
5905 +
    mark_urgent(c);
5906 +
}
5907 +
5908 +
/* Turn a system bell request associated with a surface into window urgency. */
5909 +
void ring_system_bell(struct wl_listener *listener, void *data) {
5910 +
    struct wlr_xdg_system_bell_v1_ring_event *event = data;
5911 +
    client_t                                 *c     = nullptr;
5912 +
5913 +
    toplevel_from_wlr_surface(event->surface, &c, nullptr);
5914 +
    mark_urgent(c);
5915 +
}
5916 +
5894 5917
/* Show a numbered workspace or return to the previously shown one. */
5895 5918
void view(const arg_t *arg) {
5896 5919
    /* A negative index selects the previously shown workspace. */
5897 5920
    if (!selmon)
5898 5921
        return;