2009-02-14 02:33:31 +01:00
|
|
|
|
/*
|
|
|
|
|
* vim:ts=8:expandtab
|
|
|
|
|
*
|
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
|
|
|
|
*
|
2009-02-15 03:07:29 +01:00
|
|
|
|
* © 2009 Michael Stapelberg and contributors
|
2009-02-14 02:33:31 +01:00
|
|
|
|
*
|
|
|
|
|
* See file LICENSE for license information.
|
|
|
|
|
*
|
2009-02-15 03:07:29 +01:00
|
|
|
|
* table.c: Functions/macros for easy modifying/accessing of _the_ table (defining our
|
|
|
|
|
* layout).
|
2009-02-08 04:04:35 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
#include "data.h"
|
|
|
|
|
#include "table.h"
|
2009-02-28 01:12:05 +01:00
|
|
|
|
#include "util.h"
|
2009-03-04 21:30:02 +01:00
|
|
|
|
#include "i3.h"
|
2009-05-09 17:48:35 +02:00
|
|
|
|
#include "layout.h"
|
2009-09-27 23:08:27 +02:00
|
|
|
|
#include "config.h"
|
2009-09-29 19:45:41 +02:00
|
|
|
|
#include "workspace.h"
|
2009-12-19 22:39:00 +01:00
|
|
|
|
#include "log.h"
|
2009-02-08 04:04:35 +01:00
|
|
|
|
|
2009-02-13 05:16:47 +01:00
|
|
|
|
int current_workspace = 0;
|
2009-09-27 14:00:54 +02:00
|
|
|
|
int num_workspaces = 1;
|
2009-09-29 19:45:41 +02:00
|
|
|
|
struct workspaces_head *workspaces;
|
2009-02-13 05:16:47 +01:00
|
|
|
|
/* Convenience pointer to the current workspace */
|
2009-09-27 14:00:54 +02:00
|
|
|
|
Workspace *c_ws;
|
2009-02-13 19:04:45 +01:00
|
|
|
|
int current_col = 0;
|
|
|
|
|
int current_row = 0;
|
2009-02-08 04:04:35 +01:00
|
|
|
|
|
2009-02-08 11:25:32 +01:00
|
|
|
|
/*
|
|
|
|
|
* Initialize table
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-02-08 04:04:35 +01:00
|
|
|
|
void init_table() {
|
2009-09-29 19:45:41 +02:00
|
|
|
|
workspaces = scalloc(sizeof(struct workspaces_head));
|
|
|
|
|
TAILQ_INIT(workspaces);
|
2009-02-13 05:16:47 +01:00
|
|
|
|
|
2009-09-29 19:45:41 +02:00
|
|
|
|
c_ws = scalloc(sizeof(Workspace));
|
|
|
|
|
workspace_set_name(c_ws, NULL);
|
|
|
|
|
TAILQ_INIT(&(c_ws->floating_clients));
|
|
|
|
|
TAILQ_INSERT_TAIL(workspaces, c_ws, workspaces);
|
2009-02-08 04:04:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-11-04 22:10:26 +01:00
|
|
|
|
static void new_container(Workspace *workspace, Container **container, int col, int row, bool skip_layout_switch) {
|
2009-02-14 02:33:31 +01:00
|
|
|
|
Container *new;
|
|
|
|
|
new = *container = calloc(sizeof(Container), 1);
|
|
|
|
|
CIRCLEQ_INIT(&(new->clients));
|
|
|
|
|
new->colspan = 1;
|
|
|
|
|
new->rowspan = 1;
|
2009-03-04 21:00:32 +01:00
|
|
|
|
new->col = col;
|
|
|
|
|
new->row = row;
|
2009-02-14 08:38:07 +01:00
|
|
|
|
new->workspace = workspace;
|
2009-11-04 22:10:26 +01:00
|
|
|
|
if (!skip_layout_switch)
|
|
|
|
|
switch_layout_mode(global_conn, new, config.container_mode);
|
2009-09-27 23:08:27 +02:00
|
|
|
|
new->stack_limit = config.container_stack_limit;
|
|
|
|
|
new->stack_limit_value = config.container_stack_limit_value;
|
2009-02-10 05:50:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-08 11:25:32 +01:00
|
|
|
|
/*
|
|
|
|
|
* Add one row to the table
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-02-13 05:16:47 +01:00
|
|
|
|
void expand_table_rows(Workspace *workspace) {
|
2009-02-14 02:33:31 +01:00
|
|
|
|
workspace->rows++;
|
2009-02-08 04:04:35 +01:00
|
|
|
|
|
2009-05-09 17:48:35 +02:00
|
|
|
|
workspace->height_factor = realloc(workspace->height_factor, sizeof(float) * workspace->rows);
|
|
|
|
|
workspace->height_factor[workspace->rows-1] = 0;
|
|
|
|
|
|
2009-02-15 02:30:18 +01:00
|
|
|
|
for (int c = 0; c < workspace->cols; c++) {
|
2009-02-14 02:33:31 +01:00
|
|
|
|
workspace->table[c] = realloc(workspace->table[c], sizeof(Container*) * workspace->rows);
|
2009-11-04 22:10:26 +01:00
|
|
|
|
new_container(workspace, &(workspace->table[c][workspace->rows-1]), c, workspace->rows-1, true);
|
2009-02-14 02:33:31 +01:00
|
|
|
|
}
|
2009-11-04 22:10:26 +01:00
|
|
|
|
|
|
|
|
|
/* We need to switch the layout in a separate step because it could
|
|
|
|
|
* happen that render_layout() (being called by switch_layout_mode())
|
|
|
|
|
* would access containers which were not yet initialized. */
|
|
|
|
|
for (int c = 0; c < workspace->cols; c++)
|
|
|
|
|
switch_layout_mode(global_conn, workspace->table[c][workspace->rows-1], config.container_mode);
|
2009-02-08 04:04:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-11 18:56:31 +01:00
|
|
|
|
/*
|
|
|
|
|
* Adds one row at the head of the table
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void expand_table_rows_at_head(Workspace *workspace) {
|
|
|
|
|
workspace->rows++;
|
|
|
|
|
|
2009-05-09 17:48:35 +02:00
|
|
|
|
workspace->height_factor = realloc(workspace->height_factor, sizeof(float) * workspace->rows);
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("rows = %d\n", workspace->rows);
|
2009-05-09 17:48:35 +02:00
|
|
|
|
for (int rows = (workspace->rows - 1); rows >= 1; rows--) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Moving height_factor %d (%f) to %d\n", rows-1, workspace->height_factor[rows-1], rows);
|
2009-05-09 17:48:35 +02:00
|
|
|
|
workspace->height_factor[rows] = workspace->height_factor[rows-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
workspace->height_factor[0] = 0;
|
|
|
|
|
|
2009-03-11 18:56:31 +01:00
|
|
|
|
for (int cols = 0; cols < workspace->cols; cols++)
|
|
|
|
|
workspace->table[cols] = realloc(workspace->table[cols], sizeof(Container*) * workspace->rows);
|
|
|
|
|
|
|
|
|
|
/* Move the other rows */
|
|
|
|
|
for (int cols = 0; cols < workspace->cols; cols++)
|
|
|
|
|
for (int rows = workspace->rows - 1; rows > 0; rows--) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Moving row %d to %d\n", rows-1, rows);
|
2009-03-11 18:56:31 +01:00
|
|
|
|
workspace->table[cols][rows] = workspace->table[cols][rows-1];
|
|
|
|
|
workspace->table[cols][rows]->row = rows;
|
|
|
|
|
}
|
2009-05-09 17:48:35 +02:00
|
|
|
|
|
2009-03-11 18:56:31 +01:00
|
|
|
|
for (int cols = 0; cols < workspace->cols; cols++)
|
2009-11-04 22:10:26 +01:00
|
|
|
|
new_container(workspace, &(workspace->table[cols][0]), cols, 0, false);
|
2009-03-11 18:56:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-08 11:25:32 +01:00
|
|
|
|
/*
|
|
|
|
|
* Add one column to the table
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-02-13 05:16:47 +01:00
|
|
|
|
void expand_table_cols(Workspace *workspace) {
|
2009-02-14 02:33:31 +01:00
|
|
|
|
workspace->cols++;
|
2009-02-13 05:16:47 +01:00
|
|
|
|
|
2009-05-09 17:48:35 +02:00
|
|
|
|
workspace->width_factor = realloc(workspace->width_factor, sizeof(float) * workspace->cols);
|
|
|
|
|
workspace->width_factor[workspace->cols-1] = 0;
|
|
|
|
|
|
2009-02-14 02:33:31 +01:00
|
|
|
|
workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols);
|
|
|
|
|
workspace->table[workspace->cols-1] = calloc(sizeof(Container*) * workspace->rows, 1);
|
2009-11-04 22:12:15 +01:00
|
|
|
|
|
|
|
|
|
for (int c = 0; c < workspace->rows; c++)
|
|
|
|
|
new_container(workspace, &(workspace->table[workspace->cols-1][c]), workspace->cols-1, c, true);
|
|
|
|
|
|
2009-02-15 02:30:18 +01:00
|
|
|
|
for (int c = 0; c < workspace->rows; c++)
|
2009-11-04 22:12:15 +01:00
|
|
|
|
switch_layout_mode(global_conn, workspace->table[workspace->cols-1][c], config.container_mode);
|
2009-02-08 04:04:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-11 01:55:10 +01:00
|
|
|
|
/*
|
|
|
|
|
* Inserts one column at the table’s head
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void expand_table_cols_at_head(Workspace *workspace) {
|
|
|
|
|
workspace->cols++;
|
|
|
|
|
|
2009-05-09 17:48:35 +02:00
|
|
|
|
workspace->width_factor = realloc(workspace->width_factor, sizeof(float) * workspace->cols);
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("cols = %d\n", workspace->cols);
|
2009-05-09 17:48:35 +02:00
|
|
|
|
for (int cols = (workspace->cols - 1); cols >= 1; cols--) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Moving width_factor %d (%f) to %d\n", cols-1, workspace->width_factor[cols-1], cols);
|
2009-05-09 17:48:35 +02:00
|
|
|
|
workspace->width_factor[cols] = workspace->width_factor[cols-1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
workspace->width_factor[0] = 0;
|
|
|
|
|
|
2009-03-11 01:55:10 +01:00
|
|
|
|
workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols);
|
|
|
|
|
workspace->table[workspace->cols-1] = calloc(sizeof(Container*) * workspace->rows, 1);
|
|
|
|
|
|
|
|
|
|
/* Move the other columns */
|
|
|
|
|
for (int rows = 0; rows < workspace->rows; rows++)
|
|
|
|
|
for (int cols = workspace->cols - 1; cols > 0; cols--) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Moving col %d to %d\n", cols-1, cols);
|
2009-03-11 01:55:10 +01:00
|
|
|
|
workspace->table[cols][rows] = workspace->table[cols-1][rows];
|
|
|
|
|
workspace->table[cols][rows]->col = cols;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int rows = 0; rows < workspace->rows; rows++)
|
2009-11-04 22:10:26 +01:00
|
|
|
|
new_container(workspace, &(workspace->table[0][rows]), 0, rows, false);
|
2009-03-11 01:55:10 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 08:14:00 +01:00
|
|
|
|
/*
|
|
|
|
|
* Shrinks the table by one column.
|
|
|
|
|
*
|
|
|
|
|
* The containers themselves are freed in move_columns_from() or move_rows_from(). Therefore, this
|
|
|
|
|
* function may only be called from move_*() or after making sure that the containers are freed
|
|
|
|
|
* properly.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-02-24 20:29:30 +01:00
|
|
|
|
static void shrink_table_cols(Workspace *workspace) {
|
2009-05-09 17:48:35 +02:00
|
|
|
|
float free_space = workspace->width_factor[workspace->cols-1];
|
|
|
|
|
|
2009-02-24 20:29:30 +01:00
|
|
|
|
workspace->cols--;
|
2009-03-09 06:49:11 +01:00
|
|
|
|
|
2009-05-09 17:48:35 +02:00
|
|
|
|
/* Shrink the width_factor array */
|
|
|
|
|
workspace->width_factor = realloc(workspace->width_factor, sizeof(float) * workspace->cols);
|
|
|
|
|
|
2009-03-09 06:49:11 +01:00
|
|
|
|
/* Free the container-pointers */
|
2009-02-24 20:29:30 +01:00
|
|
|
|
free(workspace->table[workspace->cols]);
|
2009-03-09 06:49:11 +01:00
|
|
|
|
|
|
|
|
|
/* Re-allocate the table */
|
2009-02-24 20:29:30 +01:00
|
|
|
|
workspace->table = realloc(workspace->table, sizeof(Container**) * workspace->cols);
|
2009-05-09 17:48:35 +02:00
|
|
|
|
|
|
|
|
|
/* Distribute the free space */
|
|
|
|
|
if (free_space == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int cols = (workspace->cols-1); cols >= 0; cols--) {
|
|
|
|
|
if (workspace->width_factor[cols] == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Added free space (%f) to %d (had %f)\n", free_space, cols,
|
2009-05-09 17:48:35 +02:00
|
|
|
|
workspace->width_factor[cols]);
|
|
|
|
|
workspace->width_factor[cols] += free_space;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-02-24 20:29:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 08:14:00 +01:00
|
|
|
|
/*
|
|
|
|
|
* See shrink_table_cols()
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-02-24 20:29:30 +01:00
|
|
|
|
static void shrink_table_rows(Workspace *workspace) {
|
2009-09-12 19:58:39 +02:00
|
|
|
|
float free_space = workspace->height_factor[workspace->rows-1];
|
|
|
|
|
|
2009-02-24 20:29:30 +01:00
|
|
|
|
workspace->rows--;
|
2009-03-09 08:14:00 +01:00
|
|
|
|
for (int cols = 0; cols < workspace->cols; cols++)
|
2009-02-24 20:29:30 +01:00
|
|
|
|
workspace->table[cols] = realloc(workspace->table[cols], sizeof(Container*) * workspace->rows);
|
|
|
|
|
|
2009-09-12 19:58:39 +02:00
|
|
|
|
/* Shrink the height_factor array */
|
|
|
|
|
workspace->height_factor = realloc(workspace->height_factor, sizeof(float) * workspace->rows);
|
|
|
|
|
|
|
|
|
|
/* Distribute the free space */
|
|
|
|
|
if (free_space == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int rows = (workspace->rows-1); rows >= 0; rows--) {
|
|
|
|
|
if (workspace->height_factor[rows] == 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Added free space (%f) to %d (had %f)\n", free_space, rows,
|
2009-09-12 19:58:39 +02:00
|
|
|
|
workspace->height_factor[rows]);
|
|
|
|
|
workspace->height_factor[rows] += free_space;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-02-24 20:29:30 +01:00
|
|
|
|
|
2009-02-08 04:04:35 +01:00
|
|
|
|
/*
|
|
|
|
|
* Performs simple bounds checking for the given column/row
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
bool cell_exists(int col, int row) {
|
2009-02-23 01:41:26 +01:00
|
|
|
|
return (col >= 0 && col < c_ws->cols) &&
|
2009-02-24 20:29:30 +01:00
|
|
|
|
(row >= 0 && row < c_ws->rows);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 08:14:00 +01:00
|
|
|
|
static void free_container(xcb_connection_t *conn, Workspace *workspace, int col, int row) {
|
|
|
|
|
Container *old_container = workspace->table[col][row];
|
2009-03-04 20:41:54 +01:00
|
|
|
|
|
2009-11-04 22:37:43 +01:00
|
|
|
|
if (old_container->mode == MODE_STACK || old_container->mode == MODE_TABBED)
|
2009-03-09 08:14:00 +01:00
|
|
|
|
leave_stack_mode(conn, old_container);
|
2009-03-04 20:41:54 +01:00
|
|
|
|
|
2009-03-09 08:14:00 +01:00
|
|
|
|
free(old_container);
|
|
|
|
|
}
|
2009-03-04 21:30:02 +01:00
|
|
|
|
|
2009-03-09 08:14:00 +01:00
|
|
|
|
static void move_columns_from(xcb_connection_t *conn, Workspace *workspace, int cols) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("firstly freeing \n");
|
2009-03-09 08:14:00 +01:00
|
|
|
|
|
|
|
|
|
/* Free the columns which are cleaned up */
|
|
|
|
|
for (int rows = 0; rows < workspace->rows; rows++)
|
|
|
|
|
free_container(conn, workspace, cols-1, rows);
|
2009-03-05 01:20:13 +01:00
|
|
|
|
|
|
|
|
|
for (; cols < workspace->cols; cols++)
|
|
|
|
|
for (int rows = 0; rows < workspace->rows; rows++) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("at col = %d, row = %d\n", cols, rows);
|
2009-03-05 01:20:13 +01:00
|
|
|
|
Container *new_container = workspace->table[cols][rows];
|
2009-02-24 20:29:30 +01:00
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("moving cols = %d to cols -1 = %d\n", cols, cols-1);
|
2009-03-04 20:41:54 +01:00
|
|
|
|
workspace->table[cols-1][rows] = new_container;
|
|
|
|
|
|
|
|
|
|
new_container->row = rows;
|
|
|
|
|
new_container->col = cols-1;
|
2009-02-24 20:29:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-04 21:30:02 +01:00
|
|
|
|
static void move_rows_from(xcb_connection_t *conn, Workspace *workspace, int rows) {
|
2009-03-09 08:14:00 +01:00
|
|
|
|
for (int cols = 0; cols < workspace->cols; cols++)
|
|
|
|
|
free_container(conn, workspace, cols, rows-1);
|
2009-03-04 20:41:54 +01:00
|
|
|
|
|
2009-03-05 01:20:13 +01:00
|
|
|
|
for (; rows < workspace->rows; rows++)
|
|
|
|
|
for (int cols = 0; cols < workspace->cols; cols++) {
|
|
|
|
|
Container *new_container = workspace->table[cols][rows];
|
2009-02-24 20:29:30 +01:00
|
|
|
|
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("moving rows = %d to rows -1 = %d\n", rows, rows - 1);
|
2009-03-04 20:41:54 +01:00
|
|
|
|
workspace->table[cols][rows-1] = new_container;
|
2009-03-05 01:20:13 +01:00
|
|
|
|
|
2009-03-04 20:41:54 +01:00
|
|
|
|
new_container->row = rows-1;
|
|
|
|
|
new_container->col = cols;
|
2009-02-24 20:29:30 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-07 19:02:07 +02:00
|
|
|
|
/*
|
|
|
|
|
* Prints the table’s contents in human-readable form for debugging
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-05 17:17:37 +01:00
|
|
|
|
void dump_table(xcb_connection_t *conn, Workspace *workspace) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("dump_table()\n");
|
2009-03-11 00:20:56 +01:00
|
|
|
|
FOR_TABLE(workspace) {
|
|
|
|
|
Container *con = workspace->table[cols][rows];
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("----\n");
|
|
|
|
|
DLOG("at col=%d, row=%d\n", cols, rows);
|
|
|
|
|
DLOG("currently_focused = %p\n", con->currently_focused);
|
2009-03-11 00:20:56 +01:00
|
|
|
|
Client *loop;
|
|
|
|
|
CIRCLEQ_FOREACH(loop, &(con->clients), clients) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("got client %08x / %s\n", loop->child, loop->name);
|
2009-03-05 17:17:37 +01:00
|
|
|
|
}
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("----\n");
|
2009-03-05 17:17:37 +01:00
|
|
|
|
}
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("done\n");
|
2009-03-05 17:17:37 +01:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-24 20:29:30 +01:00
|
|
|
|
/*
|
|
|
|
|
* Shrinks the table by "compacting" it, that is, removing completely empty rows/columns
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-02-28 01:12:05 +01:00
|
|
|
|
void cleanup_table(xcb_connection_t *conn, Workspace *workspace) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("cleanup_table()\n");
|
2009-03-03 03:40:57 +01:00
|
|
|
|
|
|
|
|
|
/* Check for empty columns if we got more than one column */
|
|
|
|
|
for (int cols = 0; (workspace->cols > 1) && (cols < workspace->cols);) {
|
2009-02-24 20:29:30 +01:00
|
|
|
|
bool completely_empty = true;
|
|
|
|
|
for (int rows = 0; rows < workspace->rows; rows++)
|
|
|
|
|
if (workspace->table[cols][rows]->currently_focused != NULL) {
|
|
|
|
|
completely_empty = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-03-03 03:40:57 +01:00
|
|
|
|
if (completely_empty) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Removing completely empty column %d\n", cols);
|
2009-02-24 20:29:30 +01:00
|
|
|
|
if (cols < (workspace->cols - 1))
|
2009-03-04 21:30:02 +01:00
|
|
|
|
move_columns_from(conn, workspace, cols+1);
|
2009-03-09 08:14:00 +01:00
|
|
|
|
else {
|
|
|
|
|
for (int rows = 0; rows < workspace->rows; rows++)
|
|
|
|
|
free_container(conn, workspace, cols, rows);
|
|
|
|
|
}
|
2009-02-24 20:29:30 +01:00
|
|
|
|
shrink_table_cols(workspace);
|
2009-03-03 03:40:57 +01:00
|
|
|
|
|
|
|
|
|
if (workspace->current_col >= workspace->cols)
|
|
|
|
|
workspace->current_col = workspace->cols - 1;
|
2009-02-24 20:29:30 +01:00
|
|
|
|
} else cols++;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-09 08:14:00 +01:00
|
|
|
|
/* Check for empty rows if we got more than one row */
|
2009-03-03 03:40:57 +01:00
|
|
|
|
for (int rows = 0; (workspace->rows > 1) && (rows < workspace->rows);) {
|
2009-02-24 20:29:30 +01:00
|
|
|
|
bool completely_empty = true;
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Checking row %d\n", rows);
|
2009-02-24 20:29:30 +01:00
|
|
|
|
for (int cols = 0; cols < workspace->cols; cols++)
|
|
|
|
|
if (workspace->table[cols][rows]->currently_focused != NULL) {
|
|
|
|
|
completely_empty = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-03-03 03:40:57 +01:00
|
|
|
|
if (completely_empty) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Removing completely empty row %d\n", rows);
|
2009-02-24 20:29:30 +01:00
|
|
|
|
if (rows < (workspace->rows - 1))
|
2009-03-04 21:30:02 +01:00
|
|
|
|
move_rows_from(conn, workspace, rows+1);
|
2009-03-09 08:14:00 +01:00
|
|
|
|
else {
|
|
|
|
|
for (int cols = 0; cols < workspace->cols; cols++)
|
|
|
|
|
free_container(conn, workspace, cols, rows);
|
|
|
|
|
}
|
2009-02-24 20:29:30 +01:00
|
|
|
|
shrink_table_rows(workspace);
|
2009-03-03 03:40:57 +01:00
|
|
|
|
|
|
|
|
|
if (workspace->current_row >= workspace->rows)
|
|
|
|
|
workspace->current_row = workspace->rows - 1;
|
2009-02-24 20:29:30 +01:00
|
|
|
|
} else rows++;
|
|
|
|
|
}
|
2009-02-26 22:23:41 +01:00
|
|
|
|
|
|
|
|
|
/* Boundary checking for current_col and current_row */
|
|
|
|
|
if (current_col >= c_ws->cols)
|
|
|
|
|
current_col = c_ws->cols-1;
|
|
|
|
|
|
|
|
|
|
if (current_row >= c_ws->rows)
|
|
|
|
|
current_row = c_ws->rows-1;
|
2009-02-28 01:12:05 +01:00
|
|
|
|
|
|
|
|
|
if (CUR_CELL->currently_focused != NULL)
|
2009-04-01 12:50:42 +02:00
|
|
|
|
set_focus(conn, CUR_CELL->currently_focused, true);
|
2009-02-08 04:04:35 +01:00
|
|
|
|
}
|
2009-03-05 17:17:37 +01:00
|
|
|
|
|
|
|
|
|
/*
|
2009-04-11 14:52:11 +02:00
|
|
|
|
* Fixes col/rowspan (makes sure there are no overlapping windows, obeys borders).
|
2009-03-05 17:17:37 +01:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void fix_colrowspan(xcb_connection_t *conn, Workspace *workspace) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("Fixing col/rowspan\n");
|
2009-03-05 17:17:37 +01:00
|
|
|
|
|
2009-03-11 00:20:56 +01:00
|
|
|
|
FOR_TABLE(workspace) {
|
|
|
|
|
Container *con = workspace->table[cols][rows];
|
|
|
|
|
if (con->colspan > 1) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("gots one with colspan %d (at %d c, %d r)\n", con->colspan, cols, rows);
|
2009-03-11 00:20:56 +01:00
|
|
|
|
while (con->colspan > 1 &&
|
2009-04-11 14:52:11 +02:00
|
|
|
|
(!cell_exists(cols + (con->colspan-1), rows) ||
|
|
|
|
|
workspace->table[cols + (con->colspan - 1)][rows]->currently_focused != NULL))
|
2009-03-11 00:20:56 +01:00
|
|
|
|
con->colspan--;
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("fixed it to %d\n", con->colspan);
|
2009-03-05 17:17:37 +01:00
|
|
|
|
}
|
2009-03-11 00:20:56 +01:00
|
|
|
|
if (con->rowspan > 1) {
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("gots one with rowspan %d (at %d c, %d r)\n", con->rowspan, cols, rows);
|
2009-03-11 00:20:56 +01:00
|
|
|
|
while (con->rowspan > 1 &&
|
2009-04-11 14:52:11 +02:00
|
|
|
|
(!cell_exists(cols, rows + (con->rowspan - 1)) ||
|
|
|
|
|
workspace->table[cols][rows + (con->rowspan - 1)]->currently_focused != NULL))
|
2009-03-11 00:20:56 +01:00
|
|
|
|
con->rowspan--;
|
2009-12-19 22:39:00 +01:00
|
|
|
|
DLOG("fixed it to %d\n", con->rowspan);
|
2009-03-11 00:20:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2009-03-05 17:17:37 +01:00
|
|
|
|
}
|