...
 
Commits (3)
  • Tinu Weber's avatar
    Add wsmbox.c · 8e6b7c12
    Tinu Weber authored
    Currently this only creates and destroys a wsmap structure.
    8e6b7c12
  • Tinu Weber's avatar
    wsmap: Add arrange and arrangebox · 46e02789
    Tinu Weber authored
    Determines the position of a box depending on its position (relative to
    what the currently selected box is), and moves it accordingly.
    46e02789
  • Tinu Weber's avatar
    Add wsmap_manages_window · 824728e1
    Tinu Weber authored
    ... and wsmbox_manages_window, as a helper function (it has to take a
    pointer to an X window variable because we're passing around pointers to
    the list - it's ugly, but it's better than the other thing I had in mind
    first...).
    824728e1
......@@ -60,6 +60,7 @@ karuiwm_sources = [
'src/statusbar.c',
'src/utils.c',
'src/workspace.c',
'src/wsmap.c',
'src/wsmbox.c',
]
......
#include "wsmap.h"
#include "config.h"
#include "list.h"
#include "log.h"
#include "wsmbox.h"
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
static void arrange(struct wsmap *wsm);
static void arrangebox(struct wsmap *wsm, struct wsmbox *box,
struct wsmbox *centre);
static void
arrange(struct wsmap *wsm)
{
struct wsmbox *box;
int unsigned i;
assert(wsm->mon);
LIST_FOR (wsm->boxes, i, box)
arrangebox(wsm, box, wsm->selbox);
}
static void
arrangebox(struct wsmap *wsm, struct wsmbox *box, struct wsmbox *centre)
{
struct config const *config = config_get();
struct position pos;
struct size boxsize;
assert(wsm->mon);
/* box dimensions */
boxsize = config->wsmbox.size;
/* start at centre of monitor */
pos.x = wsm->mon->dim.x + (int) (0.5 * (double) wsm->mon->dim.width);
pos.y = wsm->mon->dim.y + (int) (0.5 * (double) wsm->mon->dim.width);
/* shift based on offset to centre box */
pos.x += (box->pos.x - centre->pos.x) * (int signed) boxsize.width;
pos.y += (box->pos.y - centre->pos.y) * (int signed) boxsize.height;
/* shift box center to that position */
pos.x -= (int signed) boxsize.width / 2;
pos.y -= (int signed) boxsize.height / 2;
wsmbox_move(box, pos);
}
struct wsmap *
wsmap_create(void)
{
struct wsmap *wsm;
wsm = malloc(sizeof(struct wsmap));
if (!wsm)
die("Could not allocate %zu bytes for workspace map structure: %s",
sizeof(struct wsmap), strerror(errno));
wsm->boxes = list_create();
wsm->selbox = wsmbox_create_ng();
wsm->mon = NULL;
return wsm;
}
void
wsmap_destroy(struct wsmap *wsm)
{
struct wsmbox *box;
assert(!wsm->mon);
assert(wsm->boxes);
while (wsm->boxes->size > 0) {
box = wsm->boxes->elements[0];
list_remove(wsm->boxes, box, NULL);
wsmbox_destroy(box);
}
list_destroy(wsm->boxes);
wsmbox_destroy(wsm->selbox);
wsm->boxes = NULL;
free(wsm);
}
bool
wsmap_manages_window(struct wsmap *wsm, Window win)
{
assert(wsm);
assert(wsm->boxes);
return list_contains(wsm->boxes, &win,
(list_eqfunc) wsmbox_manages_window);
}
......@@ -8,8 +8,17 @@ struct wsmap {
struct workspace *target;
XSetWindowAttributes wa;
bool active;
/* ^ legacy */
struct list *boxes;
struct wsmbox *selbox;
struct monitor *mon;
};
#include "workspace.h"
struct wsmap *wsmap_create(void);
void wsmap_destroy(struct wsmap *wsm);
bool wsmap_manages_window(struct wsmap *wsm, Window win);
#endif /* ndef _KARUIWM_WSMAP_H */
......@@ -139,6 +139,12 @@ wsmbox_destroy(struct wsmbox *wb)
free(wb);
}
bool
wsmbox_manages_window(struct wsmbox *wb, Window *win)
{
return *win == wb->window;
}
bool
wsmbox_manages_workspace(struct wsmbox *wb, struct workspace *ws)
{
......
......@@ -21,6 +21,7 @@ struct wsmbox {
struct wsmbox *wsmbox_create(struct workspace *ws, struct wsmap *map);
struct wsmbox *wsmbox_create_ng(void);
void wsmbox_destroy(struct wsmbox *wb);
bool wsmbox_manages_window(struct wsmbox *wb, Window *win);
bool wsmbox_manages_workspace(struct wsmbox *wb, struct workspace *ws);
void wsmbox_move(struct wsmbox *wb, struct position pos);
void wsmbox_render(struct wsmbox *wb);
......