Ability to minimize; Iconify action

This commit is contained in:
Keith Bowes 2022-02-24 11:00:25 -05:00
parent 6aa39a5ce0
commit 0769addabd
9 changed files with 100 additions and 40 deletions

View file

@ -19,13 +19,18 @@ cairo-dock &
# Start a panel # Start a panel
(waybar || yambar) & (waybar || yambar) &
# Start a notification daemon
mako &
# Load a random wallpaper # Load a random wallpaper
oldifs=$IFS oldifs=$IFS
IFS=: IFS=:
for wpdir in ${XDG_DATA_DIRS:-${datadir:-/usr/share}}:${XDG_DATA_HOME:-~/.local/share}; data_dirs=${XDG_DATA_DIRS:-${datadir:-/usr/share}}:${XDG_DATA_HOME:-~/.local/share}
for data_dir in $data_dirs;
do do
find $wpdir -path '*/backgrounds/*.jpg' -o -path '*/backgrounds/*.png' -o -path '*/backgrounds/*.svg' \ wpdir="$data_dir/wallpapers"
-o -path '*/wallpapers/*.jpg' -o -path '*/wallpapers/*.png' -o -path '*/wallpapers/*.svg'; test -d "$wpdir" && \
find $wpdir -name '*.jpg' -o -name '*.png' -o -name '*.svg'
done | (shuf -n 1 || tail -n 1) | xargs swaybg -m fill -i & done | (shuf -n 1 || tail -n 1) | xargs swaybg -m fill -i &
IFS=$oldifs IFS=$oldifs

View file

@ -1,5 +1,5 @@
# #
# Environment variables here for Waybox # Set environment variables here for Waybox
# Copy to $XDG_CONFIG_HOME/waybox/environment to customize # Copy to $XDG_CONFIG_HOME/waybox/environment to customize
# #

View file

@ -2,7 +2,7 @@ cfdata = configuration_data()
cfdata.set('libexecdir', get_option('prefix') / get_option('libexecdir')) cfdata.set('libexecdir', get_option('prefix') / get_option('libexecdir'))
cfdata.set('localedir', get_option('prefix') / get_option('localedir')) cfdata.set('localedir', get_option('prefix') / get_option('localedir'))
cfdata.set('sysconfdir', get_option('prefix') / get_option('sysconfdir')) cfdata.set('sysconfdir', get_option('prefix') / get_option('sysconfdir'))
cfdata.set('package', meson.project_name()) cfdata.set('package', meson.project_name().to_lower())
configure_file( configure_file(
configuration: cfdata, configuration: cfdata,

View file

@ -10,11 +10,6 @@
<rules>evdev</rules> <rules>evdev</rules>
<variant>dvorak</variant> <variant>dvorak</variant>
</keyboardLayout> --> </keyboardLayout> -->
<keybind key="W-Return">
<action name="Execute">
<execute>terminal</execute>
</action>
</keybind>
<!-- Keybindings for windows --> <!-- Keybindings for windows -->
<keybind key="A-F4"> <keybind key="A-F4">
<action name="Close"/> <action name="Close"/>
@ -22,10 +17,11 @@
<keybind key="C-Escape"> <keybind key="C-Escape">
<action name="Exit"/> <action name="Exit"/>
</keybind> </keybind>
<keybind key="Print"> <keybind key="W-c">
<action name="Execute"> <action name="Reconfigure"/>
<execute>grim "$(xdg-user-dir PICTURES)/$(date +'%Y-%m-%d-%H%M%S_grim_fs.png')"</execute> </keybind>
</action> <keybind key="W-m">
<action name="Iconify"/>
</keybind> </keybind>
<keybind key="W-S-M"> <keybind key="W-S-M">
<action name="ToggleMaximize"/> <action name="ToggleMaximize"/>
@ -44,14 +40,21 @@
</action> </action>
</keybind> </keybind>
<!-- Keybindings for running applications --> <!-- Keybindings for running applications -->
<keybind key="W-Return">
<action name="Execute">
<execute>$TERMINAL</execute>
</action>
</keybind>
<keybind key="Print">
<action name="Execute">
<execute>grim "$(xdg-user-dir PICTURES)/$(date +'%Y-%m-%d-%H%M%S_grim_fs.png')"</execute>
</action>
</keybind>
<keybind key="A-F2"> <keybind key="A-F2">
<action name="Execute"> <action name="Execute">
<execute>obrun l</execute> <execute>obrun l</execute>
</action> </action>
</keybind> </keybind>
<keybind key="W-c">
<action name="Reconfigure"/>
</keybind>
<keybind key="W-e"> <keybind key="W-e">
<action name="Execute"> <action name="Execute">
<execute>konqueror || falkon</execute> <execute>konqueror || falkon</execute>
@ -59,7 +62,7 @@
</keybind> </keybind>
<keybind key="W-o"> <keybind key="W-o">
<action name="Execute"> <action name="Execute">
<execute>terminal -e mc</execute> <execute>$TERMINAL -e mc</execute>
</action> </action>
</keybind> </keybind>
<keybind key="W-w"> <keybind key="W-w">

View file

@ -31,18 +31,21 @@ struct wb_view {
#endif #endif
struct wlr_xdg_toplevel_decoration_v1 *decoration; struct wlr_xdg_toplevel_decoration_v1 *decoration;
int decoration_height;
struct wl_listener map; struct wl_listener map;
struct wl_listener unmap; struct wl_listener unmap;
struct wl_listener destroy; struct wl_listener destroy;
struct wl_listener new_popup; struct wl_listener new_popup;
struct wl_listener request_maximize; struct wl_listener request_maximize;
struct wl_listener request_minimize;
struct wl_listener request_move; struct wl_listener request_move;
struct wl_listener request_resize; struct wl_listener request_resize;
struct wl_listener surface_commit; struct wl_listener surface_commit;
bool mapped; bool mapped;
int x, y;
struct wlr_box origdim; int width, height, x, y;
struct wlr_box previous_position;
}; };
void output_frame_notify(struct wl_listener* listener, void *data); void output_frame_notify(struct wl_listener* listener, void *data);

View file

@ -101,6 +101,8 @@ static bool parse_key_bindings(struct wb_config *config, xmlXPathContextPtr ctxt
key_bind->action = ACTION_CLOSE; key_bind->action = ACTION_CLOSE;
else if (strcmp(action, "ToggleMaximize") == 0) else if (strcmp(action, "ToggleMaximize") == 0)
key_bind->action = ACTION_TOGGLE_MAXIMIZE; key_bind->action = ACTION_TOGGLE_MAXIMIZE;
else if (strcmp(action, "Iconify") == 0)
key_bind->action = ACTION_ICONIFY;
else if (strcmp(action, "Exit") == 0) else if (strcmp(action, "Exit") == 0)
key_bind->action = ACTION_EXIT; key_bind->action = ACTION_EXIT;
else if (strcmp(action, "Reconfigure") == 0) else if (strcmp(action, "Reconfigure") == 0)

View file

@ -8,6 +8,7 @@ enum action_type {
ACTION_CLOSE, ACTION_CLOSE,
ACTION_EXECUTE, ACTION_EXECUTE,
ACTION_EXIT, ACTION_EXIT,
ACTION_ICONIFY,
ACTION_NEXT_WINDOW, ACTION_NEXT_WINDOW,
ACTION_PREVIOUS_WINDOW, ACTION_PREVIOUS_WINDOW,
ACTION_RECONFIGURE, ACTION_RECONFIGURE,

View file

@ -3,15 +3,22 @@
#include "waybox/seat.h" #include "waybox/seat.h"
#include "waybox/xdg_shell.h" #include "waybox/xdg_shell.h"
static void deiconify_view(struct wb_view *view) {
if (view->xdg_toplevel->requested.minimized) {
view->xdg_toplevel->requested.minimized = false;
wl_signal_emit(&view->xdg_toplevel->events.request_minimize, view->xdg_toplevel->base);
}
}
static bool cycle_views(struct wb_server *server) { static bool cycle_views(struct wb_server *server) {
/* Cycle to the next view */ /* Cycle to the next view */
if (wl_list_length(&server->views) < 2) { if (wl_list_length(&server->views) < 1) {
return false; return false;
} }
struct wb_view *current_view = wl_container_of( struct wb_view *current_view = wl_container_of(
server->views.prev, current_view, link); server->views.prev, current_view, link);
struct wb_view *prev_view = wl_container_of( deiconify_view(current_view);
server->views.next, prev_view, link);
focus_view(current_view, current_view->xdg_toplevel->base->surface); focus_view(current_view, current_view->xdg_toplevel->base->surface);
/* Move the current view to the beginning of the list */ /* Move the current view to the beginning of the list */
wl_list_remove(&current_view->link); wl_list_remove(&current_view->link);
@ -21,13 +28,14 @@ static bool cycle_views(struct wb_server *server) {
static bool cycle_views_reverse(struct wb_server *server) { static bool cycle_views_reverse(struct wb_server *server) {
/* Cycle to the previous view */ /* Cycle to the previous view */
if (wl_list_length(&server->views) < 2) { if (wl_list_length(&server->views) < 1) {
return false; return false;
} }
struct wb_view *current_view = wl_container_of( struct wb_view *current_view = wl_container_of(
server->views.next, current_view, link); server->views.next, current_view, link);
struct wb_view *next_view = wl_container_of( struct wb_view *next_view = wl_container_of(
current_view->link.next, next_view, link); current_view->link.next, next_view, link);
deiconify_view(next_view);
focus_view(next_view, next_view->xdg_toplevel->base->surface); focus_view(next_view, next_view->xdg_toplevel->base->surface);
/* Move the current view to after the previous view in the list */ /* Move the current view to after the previous view in the list */
wl_list_remove(&current_view->link); wl_list_remove(&current_view->link);
@ -94,6 +102,18 @@ static bool handle_keybinding(struct wb_server *server, xkb_keysym_t sym, uint32
if (wlr_surface_is_xdg_surface(view->xdg_toplevel->base->surface)) if (wlr_surface_is_xdg_surface(view->xdg_toplevel->base->surface))
wl_signal_emit(&view->xdg_toplevel->events.request_maximize, view->xdg_toplevel->base); wl_signal_emit(&view->xdg_toplevel->events.request_maximize, view->xdg_toplevel->base);
return true; return true;
case ACTION_ICONIFY:
{
struct wb_view *view = wl_container_of(server->views.next, view, link);
if (wlr_surface_is_xdg_surface(view->xdg_toplevel->base->surface))
{
view->xdg_toplevel->requested.minimized = true;
wl_signal_emit(&view->xdg_toplevel->events.request_minimize, view->xdg_toplevel->base);
struct wb_view *previous_view = wl_container_of(server->views.prev, previous_view, link);
focus_view(previous_view, previous_view->xdg_toplevel->base->surface);
}
return true;
}
} }
case ACTION_RECONFIGURE: case ACTION_RECONFIGURE:
deinit_config(server->config); deinit_config(server->config);

View file

@ -53,15 +53,18 @@ static void xdg_surface_commit(struct wl_listener *listener, void *data) {
/* Called after the surface is committed */ /* Called after the surface is committed */
struct wb_view *view = wl_container_of(listener, view, surface_commit); struct wb_view *view = wl_container_of(listener, view, surface_commit);
struct wlr_xdg_surface *xdg_surface = view->xdg_toplevel->base; struct wlr_xdg_surface *xdg_surface = view->xdg_toplevel->base;
if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL) if (xdg_surface->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL ||
xdg_surface->toplevel->requested.minimized)
return; return;
struct wlr_box geo_box = {0}; struct wlr_box geo_box = {0};
wlr_xdg_surface_get_geometry(xdg_surface, &geo_box); wlr_xdg_surface_get_geometry(xdg_surface, &geo_box);
if (geo_box.x < 0 && view->x < 1) if (geo_box.x < 0 && view->x < 1)
view->x += -geo_box.x; view->x += -geo_box.x;
if (geo_box.y < 0 && view->y < 1) if (geo_box.y < 0 && view->y < 1) {
view->y += -geo_box.y; view->decoration_height = -geo_box.y;
view->y += view->decoration_height;
}
} }
static void xdg_surface_map(struct wl_listener *listener, void *data) { static void xdg_surface_map(struct wl_listener *listener, void *data) {
@ -73,6 +76,10 @@ static void xdg_surface_map(struct wl_listener *listener, void *data) {
struct wlr_box geo_box = {0}; struct wlr_box geo_box = {0};
wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box); wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box);
view->height = geo_box.height;
view->width = geo_box.width;
view->x = geo_box.x;
view->y = geo_box.y;
#if WLR_CHECK_VERSION(0, 16, 0) #if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(view->xdg_toplevel, geo_box.width, geo_box.height); wlr_xdg_toplevel_set_size(view->xdg_toplevel, geo_box.width, geo_box.height);
#else #else
@ -119,26 +126,24 @@ static void xdg_toplevel_request_maximize(struct wl_listener *listener, void *da
struct wb_view *view = wl_container_of(listener, view, request_maximize); struct wb_view *view = wl_container_of(listener, view, request_maximize);
double closest_x, closest_y; double closest_x, closest_y;
struct wlr_box geo_box;
struct wlr_output *output = NULL; struct wlr_output *output = NULL;
wlr_xdg_surface_get_geometry(surface, &geo_box); wlr_output_layout_closest_point(view->server->output_layout, output, view->x + view->width / 2, view->y + view->height / 2, &closest_x, &closest_y);
wlr_output_layout_closest_point(view->server->output_layout, output, view->x + geo_box.width / 2, view->y + geo_box.height / 2, &closest_x, &closest_y);
output = wlr_output_layout_output_at(view->server->output_layout, closest_x, closest_y); output = wlr_output_layout_output_at(view->server->output_layout, closest_x, closest_y);
bool is_maximized = surface->toplevel->current.maximized; bool is_maximized = surface->toplevel->current.maximized;
struct wlr_box usable_area = {0}; struct wlr_box usable_area = {0};
if (!is_maximized) { if (!is_maximized) {
wlr_output_effective_resolution(output, &usable_area.width, &usable_area.height); wlr_output_effective_resolution(output, &usable_area.width, &usable_area.height);
view->origdim.height = geo_box.height; view->previous_position.height = view->height;
view->origdim.width = geo_box.width; view->previous_position.width = view->width;
view->origdim.x = view->x; view->previous_position.x = view->x;
view->origdim.y = view->y; view->previous_position.y = view->y;
view->x = 0; view->x = 0;
view->y = 0; view->y = 0 + view->decoration_height;
} else { } else {
usable_area = view->origdim; usable_area = view->previous_position;
view->x = view->origdim.x; view->x = view->previous_position.x;
view->y = view->origdim.y; view->y = view->previous_position.y;
} }
#if WLR_CHECK_VERSION(0, 16, 0) #if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(surface->toplevel, usable_area.width, usable_area.height); wlr_xdg_toplevel_set_size(surface->toplevel, usable_area.width, usable_area.height);
@ -149,6 +154,24 @@ static void xdg_toplevel_request_maximize(struct wl_listener *listener, void *da
#endif #endif
} }
static void xdg_toplevel_request_minimize(struct wl_listener *listener, void *data) {
struct wlr_xdg_surface *surface = data;
struct wb_view *view = wl_container_of(listener, view, request_minimize);
bool minimize_requested = surface->toplevel->requested.minimized;
if (minimize_requested) {
view->previous_position.height = view->height;
view->previous_position.width = view->width;
view->previous_position.x = view->x;
view->previous_position.y = view->y;
view->y = 0 - view->decoration_height * 2 - view->height;
} else {
view->height = view->previous_position.height;
view->width = view->previous_position.width;
view->x = view->previous_position.x;
view->y = view->previous_position.y;
}
}
static void begin_interactive(struct wb_view *view, static void begin_interactive(struct wb_view *view,
enum wb_cursor_mode mode, uint32_t edges) { enum wb_cursor_mode mode, uint32_t edges) {
/* This function sets up an interactive move or resize operation, where the /* This function sets up an interactive move or resize operation, where the
@ -261,6 +284,8 @@ static void handle_new_xdg_surface(struct wl_listener *listener, void *data) {
struct wlr_xdg_toplevel *toplevel = view->xdg_toplevel; struct wlr_xdg_toplevel *toplevel = view->xdg_toplevel;
view->request_maximize.notify = xdg_toplevel_request_maximize; view->request_maximize.notify = xdg_toplevel_request_maximize;
wl_signal_add(&toplevel->events.request_maximize, &view->request_maximize); wl_signal_add(&toplevel->events.request_maximize, &view->request_maximize);
view->request_minimize.notify = xdg_toplevel_request_minimize;
wl_signal_add(&toplevel->events.request_minimize, &view->request_minimize);
view->request_move.notify = xdg_toplevel_request_move; view->request_move.notify = xdg_toplevel_request_move;
wl_signal_add(&toplevel->events.request_move, &view->request_move); wl_signal_add(&toplevel->events.request_move, &view->request_move);
view->request_resize.notify = xdg_toplevel_request_resize; view->request_resize.notify = xdg_toplevel_request_resize;
@ -281,13 +306,14 @@ bool view_at(struct wb_view *view,
* surface pointer to that wlr_surface and the sx and sy coordinates to the * surface pointer to that wlr_surface and the sx and sy coordinates to the
* coordinates relative to that surface's top-left corner. * coordinates relative to that surface's top-left corner.
*/ */
if (view->xdg_toplevel->base->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL)
return false;
double view_sx = lx - view->x; double view_sx = lx - view->x;
double view_sy = ly - view->y; double view_sy = ly - view->y;
double _sx, _sy; double _sx, _sy;
struct wlr_surface *_surface = NULL; struct wlr_surface *_surface = NULL;
if (view->xdg_toplevel->base->role != WLR_XDG_SURFACE_ROLE_TOPLEVEL)
return false;
_surface = wlr_xdg_surface_surface_at( _surface = wlr_xdg_surface_surface_at(
view->xdg_toplevel->base, view_sx, view_sy, &_sx, &_sy); view->xdg_toplevel->base, view_sx, view_sy, &_sx, &_sy);