Skip to content

Commit

Permalink
Implement #52
Browse files Browse the repository at this point in the history
  • Loading branch information
tudurom committed Jun 25, 2018
1 parent 44c713a commit ee0bfd3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change log

## To be: v1.4.3

* [window_put_in_grid now has two additional params to specify how many cells to
occupy](https://github.com/tudurom/windowchef/issues/52). This is not
optional. Sorry.
32 changes: 29 additions & 3 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static bool fn_direction(uint32_t *, int, char **);
static bool fn_pac(uint32_t *, int, char **);
static bool fn_mod(uint32_t *, int, char **);
static bool fn_button(uint32_t *, int, char **);
static bool fn_hack(uint32_t *, int, char **);

static void usage(char *, int);
static void version(void);
Expand Down Expand Up @@ -62,7 +63,7 @@ static struct Command c[] = {
{ "window_ver_maximize" , IPCWindowVerMaximize , 0 , NULL } ,
{ "window_monocle" , IPCWindowMonocle , 0 , NULL } ,
{ "window_close" , IPCWindowClose , 0 , NULL } ,
{ "window_put_in_grid" , IPCWindowPutInGrid , 4 , fn_naturals } ,
{ "window_put_in_grid" , IPCWindowPutInGrid , 6 , fn_hack } ,
{ "window_snap" , IPCWindowSnap , 1 , fn_position } ,
{ "window_cycle" , IPCWindowCycle , 0 , NULL } ,
{ "window_rev_cycle" , IPCWindowRevCycle , 0 , NULL } ,
Expand Down Expand Up @@ -144,8 +145,7 @@ fn_naturals(uint32_t *data, int argc, char **argv)

if (errno != 0)
return false;
else
return true;
return true;
}

static bool
Expand Down Expand Up @@ -290,6 +290,32 @@ fn_button(uint32_t *data, int argc, char **argv)
return true;
}

/*
* Kinda like fn_naturals, but each two numbers are put as 16-bit numbers
* in one uint32_t.
*/
static bool
fn_hack(uint32_t *data, int argc, char **argv)
{
int i = 0, j = 0;
unsigned long d;
do {
errno = 0;
d = strtoul(argv[i], NULL, 10);
if (i % 2 == 0) {
data[j] = d << 16U;
} else {
data[j] |= d;
j++;
}
i++;
} while (i < argc && errno == 0);

if (i % 2 == 1 || errno != 0)
return false;
return true;
}

static bool
fn_position(uint32_t *data, int argc, char **argv)
{
Expand Down
39 changes: 24 additions & 15 deletions wm.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static void update_ewmh_wm_state(struct client *);
static void handle_wm_state(struct client *, xcb_atom_t, unsigned int);

static void snap_window(struct client *, enum position);
static void grid_window(struct client *, uint32_t, uint32_t, uint32_t, uint32_t);
static void grid_window(struct client *, uint16_t, uint16_t, uint16_t, uint16_t, uint16_t, uint16_t);

static void register_event_handlers(void);
static void event_configure_request(xcb_generic_event_t *);
Expand Down Expand Up @@ -2232,36 +2232,40 @@ snap_window(struct client *client, enum position pos)
*/

static void
grid_window(struct client *client, uint32_t grid_width, uint32_t grid_height, uint32_t grid_x, uint32_t grid_y)
grid_window(struct client *client, uint16_t grid_width, uint16_t grid_height, uint16_t grid_x, uint16_t grid_y, uint16_t occ_w, uint16_t occ_h)
{
int16_t mon_x, mon_y;
uint16_t base_w, base_h;
uint16_t new_w, new_h;
uint16_t mon_w, mon_h;

if (client == NULL || grid_x >= grid_width || grid_y >= grid_height)
return;

DMSG("Gridding window in grid of size (%d, %d) pos (%d, %d) window size (%d, %d)\n", grid_width, grid_height, grid_x, grid_y, occ_w, occ_h);
if (is_maxed(client)) {
unmaximize_window(client);
set_focused(client);
}

get_monitor_size(client, &mon_x, &mon_y, &mon_w, &mon_h);

/* calculate new window size */
new_w = (mon_w - conf.gap_left - conf.gap_right - (grid_width - 1) * conf.grid_gap
base_w = (mon_w - conf.gap_left - conf.gap_right - (grid_width - 1) * conf.grid_gap
- grid_width * 2 * conf.border_width) / grid_width;

new_h = (mon_h - conf.gap_up - conf.gap_down - (grid_height - 1) * conf.grid_gap
base_h = (mon_h - conf.gap_up - conf.gap_down - (grid_height - 1) * conf.grid_gap
- grid_height * 2 * conf.border_width) / grid_height;
/* calculate new window size */
new_w = base_w * occ_w + (occ_w - 1) * (conf.grid_gap + 2 * conf.border_width);

new_h = base_h * occ_h + (occ_h - 1) * (conf.grid_gap + 2 * conf.border_width);

client->geom.width = new_w;
client->geom.height = new_h;

client->geom.x = mon_x + conf.gap_left + grid_x
* (conf.border_width + new_w + conf.border_width + conf.grid_gap);
* (conf.border_width + base_w + conf.border_width + conf.grid_gap);
client->geom.y = mon_y + conf.gap_up + grid_y
* (conf.border_width + new_h + conf.border_width + conf.grid_gap);
* (conf.border_width + base_h + conf.border_width + conf.grid_gap);

DMSG("w: %d\th: %d\n", new_w, new_h);

Expand Down Expand Up @@ -2914,18 +2918,23 @@ ipc_window_close(uint32_t *d)
static void
ipc_window_put_in_grid(uint32_t *d)
{
uint32_t grid_width, grid_height;
uint32_t grid_x, grid_y;
uint16_t grid_width, grid_height;
uint16_t grid_x, grid_y;
uint16_t occ_w, occ_h;
const uint16_t m1 = 16U, m2 = 0xffffU;

grid_width = d[0];
grid_height = d[1];
grid_x = d[2];
grid_y = d[3];
DMSG("data[4] = %d\n", d[4]);
grid_width = d[0] >> m1;
grid_height = d[0] & m2;
grid_x = d[1] >> m1;
grid_y = d[1] & m2;
occ_w = d[2] >> m1;
occ_h = d[2] & m2;

if (focused_win == NULL || grid_x >= grid_width || grid_y >= grid_height)
return;

grid_window(focused_win, grid_width, grid_height, grid_x, grid_y);
grid_window(focused_win, grid_width, grid_height, grid_x, grid_y, occ_w, occ_h);
}

static void
Expand Down

0 comments on commit ee0bfd3

Please sign in to comment.