Add functions for client geometry

This commit is contained in:
Alex Kotov 2021-11-21 03:49:19 +05:00
parent 86f72bc0d5
commit d49f1ffdf6
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
4 changed files with 150 additions and 85 deletions

View File

@ -180,8 +180,8 @@ static void pop(Client *);
static void quit(const Arg *arg); static void quit(const Arg *arg);
static Monitor *recttomon(int x, int y, int w, int h); static Monitor *recttomon(int x, int y, int w, int h);
static void resetnmaster(const Arg *arg); static void resetnmaster(const Arg *arg);
static void resize(Client *c, int x, int y, int w, int h, int bw, int interact); static void resize(Client *c, struct ClientGeometry client_geometry, int interact);
static void resizeclient(Client *c, int x, int y, int w, int h, int bw); static void resizeclient(Client *c, struct ClientGeometry client_geometry);
static void resizemouse(const Arg *arg); static void resizemouse(const Arg *arg);
static void restack(Monitor *m); static void restack(Monitor *m);
static void run(); static void run();
@ -1116,15 +1116,9 @@ void movemouse(__attribute__((unused)) const Arg *arg)
} }
if (!selmon->lt[selmon->sellt]->arrange || c->state.is_floating) { if (!selmon->lt[selmon->sellt]->arrange || c->state.is_floating) {
resize( struct ClientGeometry client_geometry = c->state.geometry;
c, position_init_from_args(&client_geometry.basic.position, nx, ny);
nx, resize(c, client_geometry, 1);
ny,
c->state.geometry.basic.sizes.w,
c->state.geometry.basic.sizes.h,
c->state.geometry.border_width,
1
);
} }
break; break;
@ -1261,21 +1255,29 @@ void resetnmaster(const Arg *arg)
arrange(selmon); arrange(selmon);
} }
void resize(Client *c, int x, int y, int w, int h, int bw, int interact) void resize(Client *c, struct ClientGeometry client_geometry, int interact)
{ {
if (applysizehints(c, &x, &y, &w, &h, bw, interact)) if (
resizeclient(c, x, y, w, h, bw); applysizehints(
c,
&client_geometry.basic.position.x,
&client_geometry.basic.position.y,
&client_geometry.basic.sizes.w,
&client_geometry.basic.sizes.h,
client_geometry.border_width,
interact
)
) {
resizeclient(c, client_geometry);
}
} }
void resizeclient(Client *c, int x, int y, int w, int h, int bw) void resizeclient(Client *c, const struct ClientGeometry client_geometry)
{ {
XWindowChanges wc; c->state.geometry = client_geometry;
c->state.geometry.basic.position.x = wc.x = x; XWindowChanges wc = { 0 };
c->state.geometry.basic.position.y = wc.y = y; client_geometry_to_x_window_changes(&client_geometry, &wc);
c->state.geometry.basic.sizes.w = wc.width = w;
c->state.geometry.basic.sizes.h = wc.height = h;
c->state.geometry.border_width = wc.border_width = bw;
XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
configure(c); configure(c);
@ -1392,15 +1394,9 @@ void resizemouse(__attribute__((unused)) const Arg *arg)
} }
if (!selmon->lt[selmon->sellt]->arrange || c->state.is_floating) { if (!selmon->lt[selmon->sellt]->arrange || c->state.is_floating) {
resize( struct ClientGeometry client_geometry = c->state.geometry;
c, sizes_init_from_args(&client_geometry.basic.sizes, nw, nh);
c->state.geometry.basic.position.x, resize(c, client_geometry, 1);
c->state.geometry.basic.position.y,
nw,
nh,
c->state.geometry.border_width,
1
);
} }
break; break;
@ -1737,15 +1733,7 @@ void showhide(Client *c)
); );
if (!c->mon->lt[c->mon->sellt]->arrange || c->state.is_floating) { if (!c->mon->lt[c->mon->sellt]->arrange || c->state.is_floating) {
resize( resize(c, c->state.geometry, 0);
c,
c->state.geometry.basic.position.x,
c->state.geometry.basic.position.y,
c->state.geometry.basic.sizes.w,
c->state.geometry.basic.sizes.h,
c->state.geometry.border_width,
0
);
} }
showhide(c->snext); showhide(c->snext);
} else { } else {
@ -1798,17 +1786,19 @@ void togglefloating(__attribute__((unused)) const Arg *arg)
const int border_width = settings_get_border_width(); const int border_width = settings_get_border_width();
if (selmon->sel->state.is_floating) { if (selmon->sel->state.is_floating) {
resize( struct ClientGeometry client_geometry = selmon->sel->state.geometry;
selmon->sel,
selmon->sel->state.geometry.basic.position.x, sizes_init_from_args(
selmon->sel->state.geometry.basic.position.y, &client_geometry.basic.sizes,
selmon->sel->state.geometry.basic.sizes.w - selmon->sel->state.geometry.basic.sizes.w -
2 * (border_width - selmon->sel->state.geometry.border_width), 2 * (border_width - selmon->sel->state.geometry.border_width),
selmon->sel->state.geometry.basic.sizes.h - selmon->sel->state.geometry.basic.sizes.h -
2 * (border_width - selmon->sel->state.geometry.border_width), 2 * (border_width - selmon->sel->state.geometry.border_width)
border_width,
0
); );
client_geometry.border_width = border_width;
resize(selmon->sel, client_geometry, 0);
} }
arrange(selmon); arrange(selmon);

View File

@ -51,16 +51,18 @@ void centeredmaster(Monitor *m)
const int right_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap; const int right_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap;
const int bottom_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap; const int bottom_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap;
resize( struct ClientGeometry client_geometry;
c, client_geometry_init_from_args(
&client_geometry,
m->window_area_geometry.position.x + mx + left_gap, m->window_area_geometry.position.x + mx + left_gap,
m->window_area_geometry.position.y + my + top_gap, m->window_area_geometry.position.y + my + top_gap,
mw - 2 * border_width - left_gap - right_gap, mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap, h - 2 * border_width - top_gap - bottom_gap,
border_width, border_width
0
); );
resize(c, client_geometry, 0);
const int total_height = const int total_height =
client_geometry_total_height(&c->state.geometry); client_geometry_total_height(&c->state.geometry);
@ -76,16 +78,18 @@ void centeredmaster(Monitor *m)
const int right_gap = bottom_right_half_gap; const int right_gap = bottom_right_half_gap;
const int bottom_gap = (i == n - 1 || i == n - 2) ? gap_size : bottom_right_half_gap; const int bottom_gap = (i == n - 1 || i == n - 2) ? gap_size : bottom_right_half_gap;
resize( struct ClientGeometry client_geometry;
c, client_geometry_init_from_args(
&client_geometry,
m->window_area_geometry.position.x + left_gap, m->window_area_geometry.position.x + left_gap,
m->window_area_geometry.position.y + ety + top_gap, m->window_area_geometry.position.y + ety + top_gap,
tw - 2 * border_width - left_gap - right_gap, tw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap, h - 2 * border_width - top_gap - bottom_gap,
border_width, border_width
0
); );
resize(c, client_geometry, 0);
const int total_height = const int total_height =
client_geometry_total_height(&c->state.geometry); client_geometry_total_height(&c->state.geometry);
@ -99,16 +103,18 @@ void centeredmaster(Monitor *m)
const int right_gap = gap_size; const int right_gap = gap_size;
const int bottom_gap = (i == n - 1 || i == n - 2) ? gap_size : bottom_right_half_gap; const int bottom_gap = (i == n - 1 || i == n - 2) ? gap_size : bottom_right_half_gap;
resize( struct ClientGeometry client_geometry;
c, client_geometry_init_from_args(
&client_geometry,
m->window_area_geometry.position.x + mx + mw + left_gap, m->window_area_geometry.position.x + mx + mw + left_gap,
m->window_area_geometry.position.y + oty + top_gap, m->window_area_geometry.position.y + oty + top_gap,
tw - 2 * border_width - left_gap - right_gap, tw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap, h - 2 * border_width - top_gap - bottom_gap,
border_width, border_width
0
); );
resize(c, client_geometry, 0);
const int total_height = const int total_height =
client_geometry_total_height(&c->state.geometry); client_geometry_total_height(&c->state.geometry);
@ -124,15 +130,17 @@ void floating(Monitor *m)
for (Client *c = m->clients; c; c = c->next) { for (Client *c = m->clients; c; c = c->next) {
if (ISVISIBLE(c) && c->state.geometry.border_width == 0) { if (ISVISIBLE(c) && c->state.geometry.border_width == 0) {
resize( struct ClientGeometry client_geometry;
c, client_geometry_init_from_args(
&client_geometry,
c->state.geometry.basic.position.x, c->state.geometry.basic.position.x,
c->state.geometry.basic.position.y, c->state.geometry.basic.position.y,
c->state.geometry.basic.sizes.w - 2 * border_width, c->state.geometry.basic.sizes.w - 2 * border_width,
c->state.geometry.basic.sizes.h - 2 * border_width, c->state.geometry.basic.sizes.h - 2 * border_width,
border_width, border_width
0
); );
resize(c, client_geometry, 0);
} }
} }
} }
@ -174,16 +182,18 @@ void horizontile(Monitor *m)
const unsigned int right_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap; const unsigned int right_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap;
const unsigned int bottom_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap; const unsigned int bottom_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap;
resize( struct ClientGeometry client_geometry;
c, client_geometry_init_from_args(
&client_geometry,
m->window_area_geometry.position.x + mx + left_gap, m->window_area_geometry.position.x + mx + left_gap,
m->window_area_geometry.position.y + top_gap, m->window_area_geometry.position.y + top_gap,
w - 2 * border_width - left_gap - right_gap, w - 2 * border_width - left_gap - right_gap,
mh - 2 * border_width - top_gap - bottom_gap, mh - 2 * border_width - top_gap - bottom_gap,
border_width, border_width
0
); );
resize(c, client_geometry, 0);
const int total_width = const int total_width =
client_geometry_total_width(&c->state.geometry); client_geometry_total_width(&c->state.geometry);
@ -199,16 +209,18 @@ void horizontile(Monitor *m)
const unsigned int right_gap = (i == n - 1) ? gap_size : bottom_right_half_gap; const unsigned int right_gap = (i == n - 1) ? gap_size : bottom_right_half_gap;
const unsigned int bottom_gap = gap_size; const unsigned int bottom_gap = gap_size;
resize( struct ClientGeometry client_geometry;
c, client_geometry_init_from_args(
&client_geometry,
m->window_area_geometry.position.x + tx + left_gap, m->window_area_geometry.position.x + tx + left_gap,
m->window_area_geometry.position.y + mh + top_gap, m->window_area_geometry.position.y + mh + top_gap,
w - 2 * border_width - left_gap - right_gap, w - 2 * border_width - left_gap - right_gap,
m->window_area_geometry.sizes.h - mh - 2 * border_width - top_gap - bottom_gap, m->window_area_geometry.sizes.h - mh - 2 * border_width - top_gap - bottom_gap,
border_width, border_width
0
); );
resize(c, client_geometry, 0);
const int total_width = const int total_width =
client_geometry_total_width(&c->state.geometry); client_geometry_total_width(&c->state.geometry);
@ -233,15 +245,17 @@ void monocle(Monitor *m)
const int border_width = helpers_border_width(1, is_fullscreen, any_is_fullscreen); const int border_width = helpers_border_width(1, is_fullscreen, any_is_fullscreen);
for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) { for (Client *c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
resize( struct ClientGeometry client_geometry;
c, client_geometry_init_from_args(
&client_geometry,
m->window_area_geometry.position.x + gap_size, m->window_area_geometry.position.x + gap_size,
m->window_area_geometry.position.y + gap_size, m->window_area_geometry.position.y + gap_size,
m->window_area_geometry.sizes.w - 2 * border_width - 2 * gap_size, m->window_area_geometry.sizes.w - 2 * border_width - 2 * gap_size,
m->window_area_geometry.sizes.h - 2 * border_width - 2 * gap_size, m->window_area_geometry.sizes.h - 2 * border_width - 2 * gap_size,
border_width, border_width
0
); );
resize(c, client_geometry, 0);
} }
} }
@ -280,16 +294,18 @@ void tile(Monitor *m)
const unsigned int right_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap; const unsigned int right_gap = n <= m->nmaster ? gap_size : bottom_right_half_gap;
const unsigned int bottom_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap; const unsigned int bottom_gap = (i == m->nmaster - 1 || i == n - 1) ? gap_size : bottom_right_half_gap;
resize( struct ClientGeometry client_geometry;
c, client_geometry_init_from_args(
&client_geometry,
m->window_area_geometry.position.x + left_gap, m->window_area_geometry.position.x + left_gap,
m->window_area_geometry.position.y + my + top_gap, m->window_area_geometry.position.y + my + top_gap,
mw - 2 * border_width - left_gap - right_gap, mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap, h - 2 * border_width - top_gap - bottom_gap,
border_width, border_width
0
); );
resize(c, client_geometry, 0);
const int total_height = const int total_height =
client_geometry_total_height(&c->state.geometry); client_geometry_total_height(&c->state.geometry);
@ -306,16 +322,18 @@ void tile(Monitor *m)
const unsigned int right_gap = gap_size; const unsigned int right_gap = gap_size;
const unsigned int bottom_gap = (i == n - 1) ? gap_size : bottom_right_half_gap; const unsigned int bottom_gap = (i == n - 1) ? gap_size : bottom_right_half_gap;
resize( struct ClientGeometry client_geometry;
c, client_geometry_init_from_args(
&client_geometry,
m->window_area_geometry.position.x + mw + left_gap, m->window_area_geometry.position.x + mw + left_gap,
m->window_area_geometry.position.y + ty + top_gap, m->window_area_geometry.position.y + ty + top_gap,
m->window_area_geometry.sizes.w - mw - 2 * border_width - left_gap - right_gap, m->window_area_geometry.sizes.w - mw - 2 * border_width - left_gap - right_gap,
h - 2 * border_width - top_gap - bottom_gap, h - 2 * border_width - top_gap - bottom_gap,
border_width, border_width
0
); );
resize(c, client_geometry, 0);
const int total_height = const int total_height =
client_geometry_total_height(&c->state.geometry); client_geometry_total_height(&c->state.geometry);

View File

@ -51,6 +51,31 @@ void client_state_init(const ClientState client_state)
client_state->is_fullscreen = false; client_state->is_fullscreen = false;
} }
void position_init_from_args(const Position position, const int x, const int y)
{
position->x = x;
position->y = y;
}
void sizes_init_from_args(const Sizes sizes, const int width, const int height)
{
sizes->w = width;
sizes->h = height;
}
void client_geometry_init_from_args(
const ClientGeometry client_geometry,
int x,
int y,
int width,
int height,
int border_width
) {
position_init_from_args(&client_geometry->basic.position, x, y);
sizes_init_from_args(&client_geometry->basic.sizes, width, height);
client_geometry->border_width = border_width;
}
int client_geometry_total_width( int client_geometry_total_width(
const struct ClientGeometry *const client_geometry const struct ClientGeometry *const client_geometry
) { ) {
@ -63,6 +88,17 @@ int client_geometry_total_height(
return client_geometry->basic.sizes.h + 2 * client_geometry->border_width; return client_geometry->basic.sizes.h + 2 * client_geometry->border_width;
} }
void client_geometry_to_x_window_changes(
const struct ClientGeometry *const client_geometry,
XWindowChanges *const x_window_changes
) {
x_window_changes->x = client_geometry->basic.position.x;
x_window_changes->y = client_geometry->basic.position.y;
x_window_changes->width = client_geometry->basic.sizes.w;
x_window_changes->height = client_geometry->basic.sizes.h;
x_window_changes->border_width = client_geometry->border_width;
}
void client_geometry_adjust_to_boundary( void client_geometry_adjust_to_boundary(
const ClientGeometry client_geometry, const ClientGeometry client_geometry,
const struct BasicGeometry *const boundary_geometry const struct BasicGeometry *const boundary_geometry

View File

@ -48,9 +48,9 @@ struct ClientState {
bool is_fixed, is_floating, is_urgent, never_focus, is_fullscreen; bool is_fixed, is_floating, is_urgent, never_focus, is_fullscreen;
}; };
/************* /******************
* Functions * * Init functions *
*************/ ******************/
void position_init(Position position); void position_init(Position position);
void sizes_init(Sizes sizes); void sizes_init(Sizes sizes);
@ -59,9 +59,30 @@ void client_geometry_init(ClientGeometry client_geometry);
void client_size_hints_init(ClientSizeHints client_size_hints); void client_size_hints_init(ClientSizeHints client_size_hints);
void client_state_init(ClientState client_state); void client_state_init(ClientState client_state);
void position_init_from_args(Position position, int x, int y);
void sizes_init_from_args(Sizes sizes, int width, int height);
void client_geometry_init_from_args(
ClientGeometry client_geometry,
int x,
int y,
int width,
int height,
int border_width
);
/*************
* Functions *
*************/
int client_geometry_total_width(const struct ClientGeometry *client_geometry); int client_geometry_total_width(const struct ClientGeometry *client_geometry);
int client_geometry_total_height(const struct ClientGeometry *client_geometry); int client_geometry_total_height(const struct ClientGeometry *client_geometry);
void client_geometry_to_x_window_changes(
const struct ClientGeometry *client_geometry,
XWindowChanges *x_window_changes
);
void client_geometry_adjust_to_boundary( void client_geometry_adjust_to_boundary(
ClientGeometry client_geometry, ClientGeometry client_geometry,
const struct BasicGeometry *boundary_geometry const struct BasicGeometry *boundary_geometry