diff --git a/Makefile b/Makefile index 01a2528..9f4f2b7 100644 --- a/Makefile +++ b/Makefile @@ -148,7 +148,8 @@ service-systemd: endif ifneq (0,${WAYLAND}) -wayland-protocols: src/wayland/protocols/wlr-layer-shell-unstable-v1.xml +wayland-protocols: src/wayland/protocols/wlr-layer-shell-unstable-v1.xml src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.xml + # TODO: write this shorter mkdir -p src/wayland/protocols wayland-scanner private-code ${DATA_DIR_WAYLAND_PROTOCOLS}/stable/xdg-shell/xdg-shell.xml src/wayland/protocols/xdg-shell.h wayland-scanner client-header ${DATA_DIR_WAYLAND_PROTOCOLS}/stable/xdg-shell/xdg-shell.xml src/wayland/protocols/xdg-shell-client-header.h @@ -158,6 +159,8 @@ wayland-protocols: src/wayland/protocols/wlr-layer-shell-unstable-v1.xml wayland-scanner private-code src/wayland/protocols/wlr-layer-shell-unstable-v1.xml src/wayland/protocols/wlr-layer-shell-unstable-v1.h wayland-scanner client-header src/wayland/protocols/idle.xml src/wayland/protocols/idle-client-header.h wayland-scanner private-code src/wayland/protocols/idle.xml src/wayland/protocols/idle.h + wayland-scanner client-header src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.xml src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1-client-header.h + wayland-scanner private-code src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.xml src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.h endif .PHONY: clean clean-dunst clean-dunstify clean-doc clean-tests clean-coverage clean-coverage-run clean-wayland-protocols diff --git a/docs/dunst.5.pod b/docs/dunst.5.pod index 4b6ed81..409a7a5 100644 --- a/docs/dunst.5.pod +++ b/docs/dunst.5.pod @@ -249,9 +249,6 @@ Place dunst notifications on the selected layer. Using overlay will cause notifications to be displayed above fullscreen windows, though this may also occur at top depending on your compositor. -In Wayland, Notifications won't be delayed when in fullscreen (like when -setting B to pushback in X11). This is a Wayland limitation. - The bottom layer is below all windows and above the background. Default: overlay @@ -648,7 +645,7 @@ but also has a lot of extra functionality. So see more see dunstctl(1). =head1 HISTORY Dunst saves a number of notifications (specified by B) in memory. -These notifications can be recalled (i.e. redisplayed) by calling +These notifications can be recalled (i.e. redisplayed) by calling B (see dunstctl(1)). Whether these notifications will time out like if they have been just send depends on the value of the B setting. @@ -663,9 +660,15 @@ Dunst has Wayland support since version 1.6.0. Because the Wayland protocol is more focused on security, some things that are possible in X11 are not possible in Wayland. Those differences are reflected in the configuration. The main things that change are that dunst on Wayland cannot use global -hotkeys (they are deprecated anyways, use dunstctl) and it cannot detect -if an application is fullscreen. If you want to see notifications when in -fullscreen, set B in the global options. +hotkeys (they are deprecated anyways, use dunstctl). + +Some dunst features on wayland might need your compositor to support a certain +protocol. Dunst will warn you if an optional feature isn't supported and will +disable the corresponding functionality. + +Fullscreen detection works on wayland with some limitations (see B). +If you want notifications to appear over fullscreen windows, set +B in the global options. Note that the same limitations exist when using xwayland. If something doesn't quite work in Wayland, please file a bug report. In the @@ -792,7 +795,7 @@ Equivalent to the C setting. The frame color color of the notification. See COLORS for possible values. -=item C (X11 only) +=item C One of show, delay, or pushback. @@ -807,7 +810,13 @@ Or pushback which is equivalent to delay with the difference that already existing notifications are paused and hidden until the focus to the fullscreen window is lost. -See B to change fullscreen behavior in Wayland +On wayland, if B is set to mouse or keyboard, the output where the +notification is located cannot be determined. So dunst will delay or pushback if +any of the outputs is fullscreen. Since the fullscreen protocol is fairly new, +you will need a recent version of a compositor that supports it. At the time of +writing, you will need the git version of sway. +See also B to change if notifications appear above fullscreen windows in +Wayland. Default: show diff --git a/src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1-client-header.h b/src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1-client-header.h new file mode 100644 index 0000000..082ba0b --- /dev/null +++ b/src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1-client-header.h @@ -0,0 +1,611 @@ +/* Generated by wayland-scanner 1.18.0 */ + +#ifndef WLR_FOREIGN_TOPLEVEL_MANAGEMENT_UNSTABLE_V1_CLIENT_PROTOCOL_H +#define WLR_FOREIGN_TOPLEVEL_MANAGEMENT_UNSTABLE_V1_CLIENT_PROTOCOL_H + +#include +#include +#include "wayland-client.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @page page_wlr_foreign_toplevel_management_unstable_v1 The wlr_foreign_toplevel_management_unstable_v1 protocol + * @section page_ifaces_wlr_foreign_toplevel_management_unstable_v1 Interfaces + * - @subpage page_iface_zwlr_foreign_toplevel_manager_v1 - list and control opened apps + * - @subpage page_iface_zwlr_foreign_toplevel_handle_v1 - an opened toplevel + * @section page_copyright_wlr_foreign_toplevel_management_unstable_v1 Copyright + *
+ *
+ * Copyright © 2018 Ilia Bozhinov
+ *
+ * Permission to use, copy, modify, distribute, and sell this
+ * software and its documentation for any purpose is hereby granted
+ * without fee, provided that the above copyright notice appear in
+ * all copies and that both that copyright notice and this permission
+ * notice appear in supporting documentation, and that the name of
+ * the copyright holders not be used in advertising or publicity
+ * pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no
+ * representations about the suitability of this software for any
+ * purpose.  It is provided "as is" without express or implied
+ * warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+ * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
+ * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
+ * THIS SOFTWARE.
+ * 
+ */ +struct wl_output; +struct wl_seat; +struct wl_surface; +struct zwlr_foreign_toplevel_handle_v1; +struct zwlr_foreign_toplevel_manager_v1; + +/** + * @page page_iface_zwlr_foreign_toplevel_manager_v1 zwlr_foreign_toplevel_manager_v1 + * @section page_iface_zwlr_foreign_toplevel_manager_v1_desc Description + * + * The purpose of this protocol is to enable the creation of taskbars + * and docks by providing them with a list of opened applications and + * letting them request certain actions on them, like maximizing, etc. + * + * After a client binds the zwlr_foreign_toplevel_manager_v1, each opened + * toplevel window will be sent via the toplevel event + * @section page_iface_zwlr_foreign_toplevel_manager_v1_api API + * See @ref iface_zwlr_foreign_toplevel_manager_v1. + */ +/** + * @defgroup iface_zwlr_foreign_toplevel_manager_v1 The zwlr_foreign_toplevel_manager_v1 interface + * + * The purpose of this protocol is to enable the creation of taskbars + * and docks by providing them with a list of opened applications and + * letting them request certain actions on them, like maximizing, etc. + * + * After a client binds the zwlr_foreign_toplevel_manager_v1, each opened + * toplevel window will be sent via the toplevel event + */ +extern const struct wl_interface zwlr_foreign_toplevel_manager_v1_interface; +/** + * @page page_iface_zwlr_foreign_toplevel_handle_v1 zwlr_foreign_toplevel_handle_v1 + * @section page_iface_zwlr_foreign_toplevel_handle_v1_desc Description + * + * A zwlr_foreign_toplevel_handle_v1 object represents an opened toplevel + * window. Each app may have multiple opened toplevels. + * + * Each toplevel has a list of outputs it is visible on, conveyed to the + * client with the output_enter and output_leave events. + * @section page_iface_zwlr_foreign_toplevel_handle_v1_api API + * See @ref iface_zwlr_foreign_toplevel_handle_v1. + */ +/** + * @defgroup iface_zwlr_foreign_toplevel_handle_v1 The zwlr_foreign_toplevel_handle_v1 interface + * + * A zwlr_foreign_toplevel_handle_v1 object represents an opened toplevel + * window. Each app may have multiple opened toplevels. + * + * Each toplevel has a list of outputs it is visible on, conveyed to the + * client with the output_enter and output_leave events. + */ +extern const struct wl_interface zwlr_foreign_toplevel_handle_v1_interface; + +/** + * @ingroup iface_zwlr_foreign_toplevel_manager_v1 + * @struct zwlr_foreign_toplevel_manager_v1_listener + */ +struct zwlr_foreign_toplevel_manager_v1_listener { + /** + * a toplevel has been created + * + * This event is emitted whenever a new toplevel window is + * created. It is emitted for all toplevels, regardless of the app + * that has created them. + * + * All initial details of the toplevel(title, app_id, states, etc.) + * will be sent immediately after this event via the corresponding + * events in zwlr_foreign_toplevel_handle_v1. + */ + void (*toplevel)(void *data, + struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1, + struct zwlr_foreign_toplevel_handle_v1 *toplevel); + /** + * the compositor has finished with the toplevel manager + * + * This event indicates that the compositor is done sending + * events to the zwlr_foreign_toplevel_manager_v1. The server will + * destroy the object immediately after sending this request, so it + * will become invalid and the client should free any resources + * associated with it. + */ + void (*finished)(void *data, + struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1); +}; + +/** + * @ingroup iface_zwlr_foreign_toplevel_manager_v1 + */ +static inline int +zwlr_foreign_toplevel_manager_v1_add_listener(struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1, + const struct zwlr_foreign_toplevel_manager_v1_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) zwlr_foreign_toplevel_manager_v1, + (void (**)(void)) listener, data); +} + +#define ZWLR_FOREIGN_TOPLEVEL_MANAGER_V1_STOP 0 + +/** + * @ingroup iface_zwlr_foreign_toplevel_manager_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_MANAGER_V1_TOPLEVEL_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_manager_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_MANAGER_V1_FINISHED_SINCE_VERSION 1 + +/** + * @ingroup iface_zwlr_foreign_toplevel_manager_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_MANAGER_V1_STOP_SINCE_VERSION 1 + +/** @ingroup iface_zwlr_foreign_toplevel_manager_v1 */ +static inline void +zwlr_foreign_toplevel_manager_v1_set_user_data(struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) zwlr_foreign_toplevel_manager_v1, user_data); +} + +/** @ingroup iface_zwlr_foreign_toplevel_manager_v1 */ +static inline void * +zwlr_foreign_toplevel_manager_v1_get_user_data(struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1) +{ + return wl_proxy_get_user_data((struct wl_proxy *) zwlr_foreign_toplevel_manager_v1); +} + +static inline uint32_t +zwlr_foreign_toplevel_manager_v1_get_version(struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1) +{ + return wl_proxy_get_version((struct wl_proxy *) zwlr_foreign_toplevel_manager_v1); +} + +/** @ingroup iface_zwlr_foreign_toplevel_manager_v1 */ +static inline void +zwlr_foreign_toplevel_manager_v1_destroy(struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1) +{ + wl_proxy_destroy((struct wl_proxy *) zwlr_foreign_toplevel_manager_v1); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_manager_v1 + * + * Indicates the client no longer wishes to receive events for new toplevels. + * However the compositor may emit further toplevel_created events, until + * the finished event is emitted. + * + * The client must not send any more requests after this one. + */ +static inline void +zwlr_foreign_toplevel_manager_v1_stop(struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_manager_v1, + ZWLR_FOREIGN_TOPLEVEL_MANAGER_V1_STOP); +} + +#ifndef ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ENUM +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ENUM +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * types of states on the toplevel + * + * The different states that a toplevel can have. These have the same meaning + * as the states with the same names defined in xdg-toplevel + */ +enum zwlr_foreign_toplevel_handle_v1_state { + /** + * the toplevel is maximized + */ + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MAXIMIZED = 0, + /** + * the toplevel is minimized + */ + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MINIMIZED = 1, + /** + * the toplevel is active + */ + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED = 2, + /** + * the toplevel is fullscreen + * @since 2 + */ + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN = 3, +}; +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN_SINCE_VERSION 2 +#endif /* ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ENUM */ + +#ifndef ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_ERROR_ENUM +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_ERROR_ENUM +enum zwlr_foreign_toplevel_handle_v1_error { + /** + * the provided rectangle is invalid + */ + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_ERROR_INVALID_RECTANGLE = 0, +}; +#endif /* ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_ERROR_ENUM */ + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * @struct zwlr_foreign_toplevel_handle_v1_listener + */ +struct zwlr_foreign_toplevel_handle_v1_listener { + /** + * title change + * + * This event is emitted whenever the title of the toplevel + * changes. + */ + void (*title)(void *data, + struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, + const char *title); + /** + * app-id change + * + * This event is emitted whenever the app-id of the toplevel + * changes. + */ + void (*app_id)(void *data, + struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, + const char *app_id); + /** + * toplevel entered an output + * + * This event is emitted whenever the toplevel becomes visible on + * the given output. A toplevel may be visible on multiple outputs. + */ + void (*output_enter)(void *data, + struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, + struct wl_output *output); + /** + * toplevel left an output + * + * This event is emitted whenever the toplevel stops being + * visible on the given output. It is guaranteed that an + * entered-output event with the same output has been emitted + * before this event. + */ + void (*output_leave)(void *data, + struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, + struct wl_output *output); + /** + * the toplevel state changed + * + * This event is emitted immediately after the + * zlw_foreign_toplevel_handle_v1 is created and each time the + * toplevel state changes, either because of a compositor action or + * because of a request in this protocol. + */ + void (*state)(void *data, + struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, + struct wl_array *state); + /** + * all information about the toplevel has been sent + * + * This event is sent after all changes in the toplevel state + * have been sent. + * + * This allows changes to the zwlr_foreign_toplevel_handle_v1 + * properties to be seen as atomic, even if they happen via + * multiple events. + */ + void (*done)(void *data, + struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1); + /** + * this toplevel has been destroyed + * + * This event means the toplevel has been destroyed. It is + * guaranteed there won't be any more events for this + * zwlr_foreign_toplevel_handle_v1. The toplevel itself becomes + * inert so any requests will be ignored except the destroy + * request. + */ + void (*closed)(void *data, + struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1); + /** + * parent change + * + * This event is emitted whenever the parent of the toplevel + * changes. + * + * No event is emitted when the parent handle is destroyed by the + * client. + * @since 3 + */ + void (*parent)(void *data, + struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, + struct zwlr_foreign_toplevel_handle_v1 *parent); +}; + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +static inline int +zwlr_foreign_toplevel_handle_v1_add_listener(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, + const struct zwlr_foreign_toplevel_handle_v1_listener *listener, void *data) +{ + return wl_proxy_add_listener((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + (void (**)(void)) listener, data); +} + +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_MAXIMIZED 0 +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_UNSET_MAXIMIZED 1 +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_MINIMIZED 2 +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_UNSET_MINIMIZED 3 +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_ACTIVATE 4 +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_CLOSE 5 +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_RECTANGLE 6 +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_DESTROY 7 +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_FULLSCREEN 8 +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_UNSET_FULLSCREEN 9 + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_TITLE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_APP_ID_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_OUTPUT_ENTER_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_OUTPUT_LEAVE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_DONE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_CLOSED_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_PARENT_SINCE_VERSION 3 + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_MAXIMIZED_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_UNSET_MAXIMIZED_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_MINIMIZED_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_UNSET_MINIMIZED_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_ACTIVATE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_CLOSE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_RECTANGLE_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_DESTROY_SINCE_VERSION 1 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_FULLSCREEN_SINCE_VERSION 2 +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + */ +#define ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_UNSET_FULLSCREEN_SINCE_VERSION 2 + +/** @ingroup iface_zwlr_foreign_toplevel_handle_v1 */ +static inline void +zwlr_foreign_toplevel_handle_v1_set_user_data(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, void *user_data) +{ + wl_proxy_set_user_data((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, user_data); +} + +/** @ingroup iface_zwlr_foreign_toplevel_handle_v1 */ +static inline void * +zwlr_foreign_toplevel_handle_v1_get_user_data(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1) +{ + return wl_proxy_get_user_data((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1); +} + +static inline uint32_t +zwlr_foreign_toplevel_handle_v1_get_version(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1) +{ + return wl_proxy_get_version((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * Requests that the toplevel be maximized. If the maximized state actually + * changes, this will be indicated by the state event. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_set_maximized(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_MAXIMIZED); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * Requests that the toplevel be unmaximized. If the maximized state actually + * changes, this will be indicated by the state event. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_unset_maximized(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_UNSET_MAXIMIZED); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * Requests that the toplevel be minimized. If the minimized state actually + * changes, this will be indicated by the state event. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_set_minimized(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_MINIMIZED); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * Requests that the toplevel be unminimized. If the minimized state actually + * changes, this will be indicated by the state event. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_unset_minimized(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_UNSET_MINIMIZED); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * Request that this toplevel be activated on the given seat. + * There is no guarantee the toplevel will be actually activated. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_activate(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, struct wl_seat *seat) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_ACTIVATE, seat); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * Send a request to the toplevel to close itself. The compositor would + * typically use a shell-specific method to carry out this request, for + * example by sending the xdg_toplevel.close event. However, this gives + * no guarantees the toplevel will actually be destroyed. If and when + * this happens, the zwlr_foreign_toplevel_handle_v1.closed event will + * be emitted. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_close(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_CLOSE); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * The rectangle of the surface specified in this request corresponds to + * the place where the app using this protocol represents the given toplevel. + * It can be used by the compositor as a hint for some operations, e.g + * minimizing. The client is however not required to set this, in which + * case the compositor is free to decide some default value. + * + * If the client specifies more than one rectangle, only the last one is + * considered. + * + * The dimensions are given in surface-local coordinates. + * Setting width=height=0 removes the already-set rectangle. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_set_rectangle(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, struct wl_surface *surface, int32_t x, int32_t y, int32_t width, int32_t height) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_RECTANGLE, surface, x, y, width, height); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * Destroys the zwlr_foreign_toplevel_handle_v1 object. + * + * This request should be called either when the client does not want to + * use the toplevel anymore or after the closed event to finalize the + * destruction of the object. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_destroy(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_DESTROY); + + wl_proxy_destroy((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * Requests that the toplevel be fullscreened on the given output. If the + * fullscreen state and/or the outputs the toplevel is visible on actually + * change, this will be indicated by the state and output_enter/leave + * events. + * + * The output parameter is only a hint to the compositor. Also, if output + * is NULL, the compositor should decide which output the toplevel will be + * fullscreened on, if at all. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_set_fullscreen(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1, struct wl_output *output) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_SET_FULLSCREEN, output); +} + +/** + * @ingroup iface_zwlr_foreign_toplevel_handle_v1 + * + * Requests that the toplevel be unfullscreened. If the fullscreen state + * actually changes, this will be indicated by the state event. + */ +static inline void +zwlr_foreign_toplevel_handle_v1_unset_fullscreen(struct zwlr_foreign_toplevel_handle_v1 *zwlr_foreign_toplevel_handle_v1) +{ + wl_proxy_marshal((struct wl_proxy *) zwlr_foreign_toplevel_handle_v1, + ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_UNSET_FULLSCREEN); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.h b/src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.h new file mode 100644 index 0000000..5c745cb --- /dev/null +++ b/src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.h @@ -0,0 +1,106 @@ +/* Generated by wayland-scanner 1.18.0 */ + +/* + * Copyright © 2018 Ilia Bozhinov + * + * Permission to use, copy, modify, distribute, and sell this + * software and its documentation for any purpose is hereby granted + * without fee, provided that the above copyright notice appear in + * all copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of + * the copyright holders not be used in advertising or publicity + * pertaining to distribution of the software without specific, + * written prior permission. The copyright holders make no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied + * warranty. + * + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + * THIS SOFTWARE. + */ + +#include +#include +#include "wayland-util.h" + +#ifndef __has_attribute +# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ +#endif + +#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4) +#define WL_PRIVATE __attribute__ ((visibility("hidden"))) +#else +#define WL_PRIVATE +#endif + +extern const struct wl_interface wl_output_interface; +extern const struct wl_interface wl_seat_interface; +extern const struct wl_interface wl_surface_interface; +extern const struct wl_interface zwlr_foreign_toplevel_handle_v1_interface; + +static const struct wl_interface *wlr_foreign_toplevel_management_unstable_v1_types[] = { + NULL, + &zwlr_foreign_toplevel_handle_v1_interface, + &wl_seat_interface, + &wl_surface_interface, + NULL, + NULL, + NULL, + NULL, + &wl_output_interface, + &wl_output_interface, + &wl_output_interface, + &zwlr_foreign_toplevel_handle_v1_interface, +}; + +static const struct wl_message zwlr_foreign_toplevel_manager_v1_requests[] = { + { "stop", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, +}; + +static const struct wl_message zwlr_foreign_toplevel_manager_v1_events[] = { + { "toplevel", "n", wlr_foreign_toplevel_management_unstable_v1_types + 1 }, + { "finished", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, +}; + +WL_PRIVATE const struct wl_interface zwlr_foreign_toplevel_manager_v1_interface = { + "zwlr_foreign_toplevel_manager_v1", 3, + 1, zwlr_foreign_toplevel_manager_v1_requests, + 2, zwlr_foreign_toplevel_manager_v1_events, +}; + +static const struct wl_message zwlr_foreign_toplevel_handle_v1_requests[] = { + { "set_maximized", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "unset_maximized", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "set_minimized", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "unset_minimized", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "activate", "o", wlr_foreign_toplevel_management_unstable_v1_types + 2 }, + { "close", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "set_rectangle", "oiiii", wlr_foreign_toplevel_management_unstable_v1_types + 3 }, + { "destroy", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "set_fullscreen", "2?o", wlr_foreign_toplevel_management_unstable_v1_types + 8 }, + { "unset_fullscreen", "2", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, +}; + +static const struct wl_message zwlr_foreign_toplevel_handle_v1_events[] = { + { "title", "s", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "app_id", "s", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "output_enter", "o", wlr_foreign_toplevel_management_unstable_v1_types + 9 }, + { "output_leave", "o", wlr_foreign_toplevel_management_unstable_v1_types + 10 }, + { "state", "a", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "done", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "closed", "", wlr_foreign_toplevel_management_unstable_v1_types + 0 }, + { "parent", "3?o", wlr_foreign_toplevel_management_unstable_v1_types + 11 }, +}; + +WL_PRIVATE const struct wl_interface zwlr_foreign_toplevel_handle_v1_interface = { + "zwlr_foreign_toplevel_handle_v1", 3, + 10, zwlr_foreign_toplevel_handle_v1_requests, + 8, zwlr_foreign_toplevel_handle_v1_events, +}; + diff --git a/src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.xml b/src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.xml new file mode 100644 index 0000000..1081337 --- /dev/null +++ b/src/wayland/protocols/wlr-foreign-toplevel-management-unstable-v1.xml @@ -0,0 +1,270 @@ + + + + Copyright © 2018 Ilia Bozhinov + + Permission to use, copy, modify, distribute, and sell this + software and its documentation for any purpose is hereby granted + without fee, provided that the above copyright notice appear in + all copies and that both that copyright notice and this permission + notice appear in supporting documentation, and that the name of + the copyright holders not be used in advertising or publicity + pertaining to distribution of the software without specific, + written prior permission. The copyright holders make no + representations about the suitability of this software for any + purpose. It is provided "as is" without express or implied + warranty. + + THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND + FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY + SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, + ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF + THIS SOFTWARE. + + + + + The purpose of this protocol is to enable the creation of taskbars + and docks by providing them with a list of opened applications and + letting them request certain actions on them, like maximizing, etc. + + After a client binds the zwlr_foreign_toplevel_manager_v1, each opened + toplevel window will be sent via the toplevel event + + + + + This event is emitted whenever a new toplevel window is created. It + is emitted for all toplevels, regardless of the app that has created + them. + + All initial details of the toplevel(title, app_id, states, etc.) will + be sent immediately after this event via the corresponding events in + zwlr_foreign_toplevel_handle_v1. + + + + + + + Indicates the client no longer wishes to receive events for new toplevels. + However the compositor may emit further toplevel_created events, until + the finished event is emitted. + + The client must not send any more requests after this one. + + + + + + This event indicates that the compositor is done sending events to the + zwlr_foreign_toplevel_manager_v1. The server will destroy the object + immediately after sending this request, so it will become invalid and + the client should free any resources associated with it. + + + + + + + A zwlr_foreign_toplevel_handle_v1 object represents an opened toplevel + window. Each app may have multiple opened toplevels. + + Each toplevel has a list of outputs it is visible on, conveyed to the + client with the output_enter and output_leave events. + + + + + This event is emitted whenever the title of the toplevel changes. + + + + + + + This event is emitted whenever the app-id of the toplevel changes. + + + + + + + This event is emitted whenever the toplevel becomes visible on + the given output. A toplevel may be visible on multiple outputs. + + + + + + + This event is emitted whenever the toplevel stops being visible on + the given output. It is guaranteed that an entered-output event + with the same output has been emitted before this event. + + + + + + + Requests that the toplevel be maximized. If the maximized state actually + changes, this will be indicated by the state event. + + + + + + Requests that the toplevel be unmaximized. If the maximized state actually + changes, this will be indicated by the state event. + + + + + + Requests that the toplevel be minimized. If the minimized state actually + changes, this will be indicated by the state event. + + + + + + Requests that the toplevel be unminimized. If the minimized state actually + changes, this will be indicated by the state event. + + + + + + Request that this toplevel be activated on the given seat. + There is no guarantee the toplevel will be actually activated. + + + + + + + The different states that a toplevel can have. These have the same meaning + as the states with the same names defined in xdg-toplevel + + + + + + + + + + + This event is emitted immediately after the zlw_foreign_toplevel_handle_v1 + is created and each time the toplevel state changes, either because of a + compositor action or because of a request in this protocol. + + + + + + + + This event is sent after all changes in the toplevel state have been + sent. + + This allows changes to the zwlr_foreign_toplevel_handle_v1 properties + to be seen as atomic, even if they happen via multiple events. + + + + + + Send a request to the toplevel to close itself. The compositor would + typically use a shell-specific method to carry out this request, for + example by sending the xdg_toplevel.close event. However, this gives + no guarantees the toplevel will actually be destroyed. If and when + this happens, the zwlr_foreign_toplevel_handle_v1.closed event will + be emitted. + + + + + + The rectangle of the surface specified in this request corresponds to + the place where the app using this protocol represents the given toplevel. + It can be used by the compositor as a hint for some operations, e.g + minimizing. The client is however not required to set this, in which + case the compositor is free to decide some default value. + + If the client specifies more than one rectangle, only the last one is + considered. + + The dimensions are given in surface-local coordinates. + Setting width=height=0 removes the already-set rectangle. + + + + + + + + + + + + + + + + This event means the toplevel has been destroyed. It is guaranteed there + won't be any more events for this zwlr_foreign_toplevel_handle_v1. The + toplevel itself becomes inert so any requests will be ignored except the + destroy request. + + + + + + Destroys the zwlr_foreign_toplevel_handle_v1 object. + + This request should be called either when the client does not want to + use the toplevel anymore or after the closed event to finalize the + destruction of the object. + + + + + + + + Requests that the toplevel be fullscreened on the given output. If the + fullscreen state and/or the outputs the toplevel is visible on actually + change, this will be indicated by the state and output_enter/leave + events. + + The output parameter is only a hint to the compositor. Also, if output + is NULL, the compositor should decide which output the toplevel will be + fullscreened on, if at all. + + + + + + + Requests that the toplevel be unfullscreened. If the fullscreen state + actually changes, this will be indicated by the state event. + + + + + + + + This event is emitted whenever the parent of the toplevel changes. + + No event is emitted when the parent handle is destroyed by the client. + + + + + diff --git a/src/wayland/wl.c b/src/wayland/wl.c index 74b501e..b5b8c7d 100644 --- a/src/wayland/wl.c +++ b/src/wayland/wl.c @@ -19,6 +19,8 @@ #include "protocols/xdg-shell.h" #include "protocols/wlr-layer-shell-unstable-v1-client-header.h" #include "protocols/wlr-layer-shell-unstable-v1.h" +#include "protocols/wlr-foreign-toplevel-management-unstable-v1-client-header.h" +#include "protocols/wlr-foreign-toplevel-management-unstable-v1.h" #include "protocols/idle-client-header.h" #include "protocols/idle.h" #include "pool-buffer.h" @@ -56,6 +58,7 @@ struct wl_ctx { struct wl_callback *frame_callback; struct org_kde_kwin_idle *idle_handler; struct org_kde_kwin_idle_timeout *idle_timeout; + struct zwlr_foreign_toplevel_manager_v1 *toplevel_manager; bool configured; bool dirty; bool is_idle; @@ -88,9 +91,10 @@ struct dunst_output { uint32_t scale; uint32_t subpixel; // TODO do something with it + bool fullscreen; + struct zwlr_foreign_toplevel_handle_v1 *fullscreen_toplevel; // the toplevel that is fullscreened on this output }; - struct wl_ctx ctx; static void noop() { @@ -133,6 +137,7 @@ static void create_output( struct wl_output *wl_output, uint32_t global_name) { output->wl_output = wl_output; // TODO: Fix this output->scale = 1; + output->fullscreen = false; wl_list_insert(&ctx.outputs, &output->link); wl_output_set_user_data(wl_output, output); @@ -209,8 +214,6 @@ static const struct wl_touch_listener touch_listener = { .motion = touch_handle_motion, .frame = noop, .cancel = noop, - .shape = noop, - .orientation = noop, }; static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, @@ -334,28 +337,166 @@ static void add_seat_to_idle_handler(struct wl_seat *seat) { ctx.has_idle_monitor = true; } +// Warning, can return NULL +static struct dunst_output *get_configured_output() { + + switch (settings.f_mode){ + case FOLLOW_NONE: ; // this semicolon is neccesary + int n = 0; + int target_monitor = settings.monitor; + + struct dunst_output *output; + wl_list_for_each(output, &ctx.outputs, link) { + if (n == target_monitor) + return output; + n++; + } + LOG_W("Monitor %i doesn't exist, using focused monitor", settings.monitor); + return NULL; + case FOLLOW_MOUSE: + // fallthrough + case FOLLOW_KEYBOARD: + // fallthrough + default: + return NULL; + } +} + +// does not do null checking +static void dunst_output_set_fullscreen(struct dunst_output *output, + struct zwlr_foreign_toplevel_handle_v1 *toplevel, + bool fullscreen) { + output->fullscreen = fullscreen; + if (fullscreen) + output->fullscreen_toplevel = toplevel; + else + output->fullscreen_toplevel = NULL; + + LOG_D("Set output %i fullscreen state %i", output->global_name, fullscreen); + wake_up(); +} + +static void toplevel_output_leave(void *data, + struct zwlr_foreign_toplevel_handle_v1 *toplevel, + struct wl_output *output) { + zwlr_foreign_toplevel_handle_v1_set_user_data(toplevel, NULL); +} + +static void toplevel_output_enter(void *data, + struct zwlr_foreign_toplevel_handle_v1 *toplevel, + struct wl_output *output) { + // FIXME toplevel can be on multiple outputs, so a list of outputs should be kept + zwlr_foreign_toplevel_handle_v1_set_user_data(toplevel, output); +} + +static void toplevel_closed(void *data, + struct zwlr_foreign_toplevel_handle_v1 *toplevel) { + struct wl_output *output_wl = (struct wl_output*) data; + + if (output_wl == NULL) { + return; + } + struct dunst_output *output = (struct dunst_output*) wl_output_get_user_data(output_wl); + + if (output == NULL) { + return; + } + dunst_output_set_fullscreen(output, toplevel, false); +} + +static void toplevel_state(void *data, + struct zwlr_foreign_toplevel_handle_v1 *toplevel, + struct wl_array *state) { + struct wl_output *output_wl = (struct wl_output*) data; + if (output_wl == NULL) { + return; + } + struct dunst_output *output = (struct dunst_output*) wl_output_get_user_data(output_wl); + if (output == NULL) { + return; + } + + bool fullscreen = false; + bool activated = false; + enum zwlr_foreign_toplevel_handle_v1_state* element; + wl_array_for_each(element, state){ + if (*element == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN) { + fullscreen = true; + } + if (*element == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED) { + activated = true; + } + } + if (fullscreen && activated) { + dunst_output_set_fullscreen(output, toplevel, true); + + } else { + if (output->fullscreen_toplevel == toplevel) { + // this toplevel was fullscreen, but isn't anymore + dunst_output_set_fullscreen(output, toplevel, false); + } + } +} + +static const struct zwlr_foreign_toplevel_handle_v1_listener foreign_toplevel_handle_listener = { + .title = noop, + .app_id = noop, + .output_enter = toplevel_output_enter, + .output_leave = toplevel_output_leave, + .state = toplevel_state, + .done = noop, + .closed = toplevel_closed, +}; + +static void toplevel_created(void *data, + struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1, + struct zwlr_foreign_toplevel_handle_v1 *toplevel){ + zwlr_foreign_toplevel_handle_v1_add_listener(toplevel, &foreign_toplevel_handle_listener, NULL); +} + +static void toplevel_finished(void *data, + struct zwlr_foreign_toplevel_manager_v1 *zwlr_foreign_toplevel_manager_v1){ +} + +static const struct zwlr_foreign_toplevel_manager_v1_listener foreign_toplevel_manager_listener = { + .toplevel = toplevel_created, + .finished = toplevel_finished, +}; + static void handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) { - if (strcmp(interface, wl_compositor_interface.name) == 0) { - ctx.compositor = wl_registry_bind(registry, name, - &wl_compositor_interface, 4); - } else if (strcmp(interface, wl_shm_interface.name) == 0) { - ctx.shm = wl_registry_bind(registry, name, - &wl_shm_interface, 1); - } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { - ctx.layer_shell = wl_registry_bind(registry, name, - &zwlr_layer_shell_v1_interface, 1); - } else if (strcmp(interface, wl_seat_interface.name) == 0) { - ctx.seat = wl_registry_bind(registry, name, &wl_seat_interface, 3); - wl_seat_add_listener(ctx.seat, &seat_listener, ctx.seat); - add_seat_to_idle_handler(ctx.seat); - } else if (strcmp(interface, wl_output_interface.name) == 0) { - struct wl_output *output = - wl_registry_bind(registry, name, &wl_output_interface, 3); - create_output(output, name); - } else if (strcmp(interface, org_kde_kwin_idle_interface.name) == 0 && - version >= ORG_KDE_KWIN_IDLE_TIMEOUT_IDLE_SINCE_VERSION) { - ctx.idle_handler = wl_registry_bind(registry, name, &org_kde_kwin_idle_interface, 1); + int *count = data; + if (*count == 0) + { + if (strcmp(interface, wl_compositor_interface.name) == 0) { + ctx.compositor = wl_registry_bind(registry, name, + &wl_compositor_interface, 4); + } else if (strcmp(interface, wl_shm_interface.name) == 0) { + ctx.shm = wl_registry_bind(registry, name, + &wl_shm_interface, 1); + } else if (strcmp(interface, zwlr_layer_shell_v1_interface.name) == 0) { + ctx.layer_shell = wl_registry_bind(registry, name, + &zwlr_layer_shell_v1_interface, 1); + } else if (strcmp(interface, wl_seat_interface.name) == 0) { + ctx.seat = wl_registry_bind(registry, name, &wl_seat_interface, 3); + wl_seat_add_listener(ctx.seat, &seat_listener, ctx.seat); + add_seat_to_idle_handler(ctx.seat); + } else if (strcmp(interface, wl_output_interface.name) == 0) { + struct wl_output *output = + wl_registry_bind(registry, name, &wl_output_interface, 3); + create_output(output, name); + } else if (strcmp(interface, org_kde_kwin_idle_interface.name) == 0 && + version >= ORG_KDE_KWIN_IDLE_TIMEOUT_IDLE_SINCE_VERSION) { + ctx.idle_handler = wl_registry_bind(registry, name, &org_kde_kwin_idle_interface, 1); + } + } else { + if (strcmp(interface, zwlr_foreign_toplevel_manager_v1_interface.name) == 0 && + version >= ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_FULLSCREEN_SINCE_VERSION) { + // Only bind after the second pass to bind after binding to all the outputs. + // This is because otherwise toplevel_enter evens won't be sent. + ctx.toplevel_manager = wl_registry_bind(registry, name, &zwlr_foreign_toplevel_manager_v1_interface, 2); + zwlr_foreign_toplevel_manager_v1_add_listener(ctx.toplevel_manager, &foreign_toplevel_manager_listener, NULL); + } } } @@ -386,8 +527,15 @@ bool init_wayland() { return false; } + int count = 0; ctx.registry = wl_display_get_registry(ctx.display); - wl_registry_add_listener(ctx.registry, ®istry_listener, NULL); + wl_registry_add_listener(ctx.registry, ®istry_listener, &count); + wl_display_roundtrip(ctx.display); + + count = 1; + // we need a second pass to let for foreign_toplevel (look there for more info) + ctx.registry = wl_display_get_registry(ctx.display); + wl_registry_add_listener(ctx.registry, ®istry_listener, &count); wl_display_roundtrip(ctx.display); if (ctx.compositor == NULL) { @@ -414,6 +562,10 @@ bool init_wayland() { } } + if (ctx.toplevel_manager == NULL) { + LOG_W("compositor doesn't support zwlr_foreign_toplevel_v1. Fullscreen detection won't work"); + } + return true; } @@ -448,30 +600,6 @@ void finish_wayland() { org_kde_kwin_idle_timeout_release(ctx.idle_timeout); } -static struct dunst_output *get_configured_output() { - struct dunst_output *output; - - switch (settings.f_mode){ - case FOLLOW_NONE: ; // this semicolon is neccesary - int n = 0; - int target_monitor = settings.monitor; - - wl_list_for_each(output, &ctx.outputs, link) { - if (n == target_monitor) - return output; - n++; - } - LOG_W("Monitor %i doesn't exist, using focused monitor", settings.monitor); - return NULL; - case FOLLOW_MOUSE: - // fallthrough - case FOLLOW_KEYBOARD: - // fallthrough - default: - return NULL; - } -} - static void schedule_frame_and_commit(); // Draw and commit a new frame. @@ -721,7 +849,26 @@ bool wl_is_idle(void) { return ctx.is_idle; } } + bool wl_have_fullscreen_window(void) { - return false; + bool have_fullscreen = false; + + struct dunst_output *current_output = get_configured_output(); + + if (!current_output) { + // Cannot detect focused output, so return true if any of the + // outputs is fullscreen. This will work even when unfocused + // outputs have fullscreen toplevels, since a toplevel has to + // be fullscreen and activate to consider an output fullscreen. + struct dunst_output *output; + wl_list_for_each(output, &ctx.outputs, link) { + have_fullscreen |= output->fullscreen; + } + } else { + have_fullscreen = current_output->fullscreen; + } + + LOG_D("Fullscreen queried: %i", have_fullscreen); + return have_fullscreen; } /* vim: set ft=c tabstop=8 shiftwidth=8 expandtab textwidth=0: */