/* Let’s see if this was on the borders (= resize). If not, we’re done */
LOG("press button on x=%d, y=%d\n", event->event_x, event->event_y);
resize_orientation_t orientation = O_VERTICAL;
- Container *con = client->container,
- *first = NULL,
- *second = NULL;
+ Container *con = client->container;
+ int first, second;
if (con == NULL) {
LOG("dock. done.\n");
/* This was a press on the top border */
if (con->row == 0)
return 1;
- first = con->workspace->table[con->col][con->row-1];
- second = con;
+ first = con->row - 1;
+ second = con->row;
orientation = O_HORIZONTAL;
} else if (event->event_y >= (client->rect.height - 2)) {
/* …bottom border */
- if (con->row == (con->workspace->rows-1))
+ first = con->row + (con->rowspan - 1);
+ if (!cell_exists(con->col, first) ||
+ (first == (con->workspace->rows-1)))
return 1;
- first = con;
- second = con->workspace->table[con->col][con->row+1];
+
+ second = first + 1;
orientation = O_HORIZONTAL;
} else if (event->event_x <= 2) {
/* …left border */
if (con->col == 0)
return 1;
- first = con->workspace->table[con->col-1][con->row];
- second = con;
+
+ first = con->col - 1;
+ second = con->col;
} else if (event->event_x > 2) {
/* …right border */
- if (con->col == (con->workspace->cols-1))
+ first = con->col + (con->colspan - 1);
+ LOG("column %d\n", first);
+
+ if (!cell_exists(first, con->row) ||
+ (first == (con->workspace->cols-1)))
return 1;
- first = con;
- second = con->workspace->table[con->col+1][con->row];
+
+ second = first + 1;
}
- return resize_graphical_handler(conn, first, second, orientation, event);
+ return resize_graphical_handler(conn, con->workspace, first, second, orientation, event);
}
/*
* the table column/row.
*
*/
-int resize_graphical_handler(xcb_connection_t *conn, Container *first, Container *second,
+int resize_graphical_handler(xcb_connection_t *conn, Workspace *ws, int first, int second,
resize_orientation_t orientation, xcb_button_press_event_t *event) {
int new_position;
xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
xcb_destroy_window(conn, grabwin);
xcb_flush(conn);
- Workspace *ws = first->workspace;
if (orientation == O_VERTICAL) {
LOG("Resize was from X = %d to X = %d\n", event->root_x, new_position);
if (event->root_x == new_position) {
if (old_unoccupied_x == 0)
old_unoccupied_x = ws->rect.width;
- if (ws->width_factor[first->col] == 0)
+ if (ws->width_factor[first] == 0)
new_unoccupied_x += default_width;
- if (ws->width_factor[second->col] == 0)
+ if (ws->width_factor[second] == 0)
new_unoccupied_x += default_width;
LOG("\n\n\n");
LOG("old_unoccupied_x = %d\n", old_unoccupied_x);
- LOG("Updating first (before = %f)\n", ws->width_factor[first->col]);
+ LOG("Updating first (before = %f)\n", ws->width_factor[first]);
/* Convert 0 (for default width_factor) to actual numbers */
- if (ws->width_factor[first->col] == 0)
- ws->width_factor[first->col] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x;
-
- LOG("middle = %f\n", ws->width_factor[first->col]);
- LOG("first->width = %d, new_position = %d, event->root_x = %d\n", first->width, new_position, event->root_x);
- ws->width_factor[first->col] *= (float)(first->width + (new_position - event->root_x)) / first->width;
- LOG("-> %f\n", ws->width_factor[first->col]);
-
-
- LOG("Updating second (before = %f)\n", ws->width_factor[second->col]);
- if (ws->width_factor[second->col] == 0)
- ws->width_factor[second->col] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x;
- LOG("middle = %f\n", ws->width_factor[second->col]);
- LOG("second->width = %d, new_position = %d, event->root_x = %d\n", second->width, new_position, event->root_x);
- ws->width_factor[second->col] *= (float)(second->width - (new_position - event->root_x)) / second->width;
- LOG("-> %f\n", ws->width_factor[second->col]);
+ if (ws->width_factor[first] == 0)
+ ws->width_factor[first] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x;
+
+ LOG("middle = %f\n", ws->width_factor[first]);
+ int old_width = ws->width_factor[first] * old_unoccupied_x;
+ LOG("first->width = %d, new_position = %d, event->root_x = %d\n", old_width, new_position, event->root_x);
+ ws->width_factor[first] *= (float)(old_width + (new_position - event->root_x)) / old_width;
+ LOG("-> %f\n", ws->width_factor[first]);
+
+
+ LOG("Updating second (before = %f)\n", ws->width_factor[second]);
+ if (ws->width_factor[second] == 0)
+ ws->width_factor[second] = ((float)ws->rect.width / ws->cols) / new_unoccupied_x;
+ LOG("middle = %f\n", ws->width_factor[second]);
+ old_width = ws->width_factor[second] * old_unoccupied_x;
+ LOG("second->width = %d, new_position = %d, event->root_x = %d\n", old_width, new_position, event->root_x);
+ ws->width_factor[second] *= (float)(old_width - (new_position - event->root_x)) / old_width;
+ LOG("-> %f\n", ws->width_factor[second]);
LOG("new unoccupied_x = %d\n", get_unoccupied_x(ws));