Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added "expo"(spaces) style mode, with commandline option eg "skippy-xd -ad" #19

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3071bc4
added vec math helpers
Aug 18, 2013
5eaec35
added vec math helpers
Aug 18, 2013
4272ac3
refactored layout calculation , moved entirely into 'layout', to deco…
Aug 18, 2013
a1e8988
refactored layout calculation , moved entirely into 'layout', to deco…
Aug 18, 2013
8d013a5
o
Aug 18, 2013
5f6d35e
remove error messages and disable broken animation attempt
Aug 18, 2013
c75f8d5
added PosSize type, more inline with existing codebase's tendancy to …
Aug 18, 2013
9828ea5
added PosSize type, more inline with existing codebase's tendancy to …
Aug 18, 2013
ed050b7
refactor in progress, added sw_pos etc abstractions
Aug 18, 2013
4861c8d
refactor in progress, added sw_pos etc abstractions
Aug 18, 2013
b5b5387
just broke layout algo for original method, whilst cleaning up... :(
Aug 18, 2013
c359736
fixed original layout
Aug 18, 2013
58bdec7
got grid mode, and crude animation
Aug 19, 2013
2e5e4fe
added grid mode, placeholder anim, should be disabled
Aug 19, 2013
83fb3e2
some cleanup, and wrote 'scale-within-region, though its aspect-ratio…
Aug 19, 2013
5f528f9
ok
Aug 19, 2013
0d96be7
added anim time to config file, cleanup a few math helpers
Aug 19, 2013
f90458e
minor cleanup
Aug 19, 2013
65b9dd8
Added x/y sorting to grid layout
Aug 19, 2013
caf3c9e
Added x/y sorting to grid layout
Aug 19, 2013
19d7276
Added x/y sorting to grid layout
Aug 19, 2013
b482796
fixed aspect ratio row/col calculation forgrid mode
Aug 19, 2013
cb545da
changed aspect ratio calculatoin again
Aug 19, 2013
17d0c0b
disabled hacky animation as default. set 'animTime>0' to get it back'
Aug 19, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 75 additions & 21 deletions src/clientwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ clientwin_cmp_func(dlist *l, void *data)
{
return ((ClientWin*)l->data)->client.window == (Window)data;
}

//int g_all_desktops=1;
int
clientwin_validate_func(dlist *l, void *data) {
ClientWin *cw = (ClientWin *)l->data;
Expand All @@ -40,10 +40,11 @@ clientwin_validate_func(dlist *l, void *data) {
CARD32 desktop = (*(CARD32*)data),
w_desktop = wm_get_window_desktop(mw->ps->dpy, cw->client.window);

// Todo: resolve how multi-desktops vs multi-monitor works.
#ifdef CFG_XINERAMA
if(mw->xin_active && ! INTERSECTS(cw->client.x, cw->client.y, cw->client.width, cw->client.height,
if(!(mw->ps->o.xinerama_showAll) && mw->xin_active && (!INTERSECTS(cw->client.x, cw->client.y, cw->client.width, cw->client.height,
mw->xin_active->x_org, mw->xin_active->y_org,
mw->xin_active->width, mw->xin_active->height))
mw->xin_active->width, mw->xin_active->height)))
return 0;
#endif

Expand Down Expand Up @@ -200,11 +201,12 @@ static void
clientwin_repaint(ClientWin *cw, XRectangle *rect)
{
XRenderColor *tint = cw->focused ? &cw->mainwin->highlightTint : &cw->mainwin->normalTint;
int s_x = (double)rect->x * cw->factor,
/* int s_x = (double)rect->x * cw->factor,
s_y = (double)rect->y * cw->factor,
s_w = (double)rect->width * cw->factor,
s_h = (double)rect->height * cw->factor;

*/
int s_x=0,s_y=0, s_w=cw->mini.width, s_h=cw->mini.height;
if(cw->mainwin->ps->o.lazyTrans)
{
XRenderComposite(cw->mainwin->ps->dpy, PictOpSrc, cw->origin,
Expand All @@ -214,6 +216,7 @@ clientwin_repaint(ClientWin *cw, XRectangle *rect)
else
{
XRenderComposite(cw->mainwin->ps->dpy, PictOpSrc, cw->mainwin->background, None, cw->destination, cw->mini.x + s_x, cw->mini.y + s_y, 0, 0, s_x, s_y, s_w, s_h);

XRenderComposite(cw->mainwin->ps->dpy, PictOpOver, cw->origin,
cw->focused ? cw->mainwin->highlightPicture : cw->mainwin->normalPicture,
cw->destination, s_x, s_y, 0, 0, s_x, s_y, s_w, s_h);
Expand All @@ -230,8 +233,8 @@ clientwin_render(ClientWin *cw)
{
XRectangle rect;
rect.x = rect.y = 0;
rect.width = cw->client.width;
rect.height = cw->client.height;
rect.width = cw->mini.width;
rect.height = cw->mini.height;
clientwin_repaint(cw, &rect);
}

Expand Down Expand Up @@ -262,44 +265,85 @@ clientwin_schedule_repair(ClientWin *cw, XRectangle *area)
cw->damaged = true;
}

void
clientwin_move(ClientWin *cw, float f, int x, int y)
{
/* int border = MAX(1, (double)DISTANCE(cw->mainwin) * f * 0.25); */
int border = 0;
XSetWindowBorderWidth(cw->mainwin->ps->dpy, cw->mini.window, border);

cw->factor = f;
cw->mini.x = x + (int)cw->x * f;
cw->mini.y = y + (int)cw->y * f;
// This functionality moved into layout -"layout_run_scale_all".
void clientwin_move_sub(ClientWin* cw, int dx,int dy,float f) {
printf("OBSELETE\n");
// cw->factor = f;
cw->mini.x = dx + (int)cw->x * f;
cw->mini.y = dy + (int)cw->y * f;
if(cw->mainwin->ps->o.lazyTrans)
{
cw->mini.x += cw->mainwin->x;
cw->mini.y += cw->mainwin->y;
}
cw->mini.width = MAX(1, (int)cw->client.width * f);
cw->mini.height = MAX(1, (int)cw->client.height * f);

}


void
clientwin_move_and_create_scaled_image(ClientWin *cw, float f, int dx, int dy) {
clientwin_move_sub(cw, dx,dy,f);
clientwin_create_scaled_image( cw);
}
void
clientwin_create_scaled_image(ClientWin *cw)
{
/* int border = MAX(1, (double)DISTANCE(cw->mainwin) * f * 0.25); */
int border = 0;
XSetWindowBorderWidth(cw->mainwin->ps->dpy, cw->mini.window, border);

XMoveResizeWindow(cw->mainwin->ps->dpy, cw->mini.window, cw->mini.x - border, cw->mini.y - border, cw->mini.width, cw->mini.height);

if(cw->pixmap)
XFreePixmap(cw->mainwin->ps->dpy, cw->pixmap);

if(cw->destination)
XRenderFreePicture(cw->mainwin->ps->dpy, cw->destination);

printf("create image %d %d %d %d\n",cw->mini.x,cw->mini.y, cw->mini.width,cw->mini.height);
cw->pixmap = XCreatePixmap(cw->mainwin->ps->dpy, cw->mini.window, cw->mini.width, cw->mini.height, cw->mainwin->depth);
XSetWindowBackgroundPixmap(cw->mainwin->ps->dpy, cw->mini.window, cw->pixmap);

cw->destination = XRenderCreatePicture(cw->mainwin->ps->dpy, cw->pixmap, cw->mini.format, 0, 0);
}


void
clientwin_lerp_client_to_mini(ClientWin* cw,float t){
Rect2i dst_rc=sw_rect(&cw->mini);
Rect2i src_rc=sw_rect(&cw->client);
int denom=1<<12;
int ti=(int)(t*(float)denom);
Rect2i rc;
rc.min=v2i_lerp(src_rc.min,dst_rc.min, ti, denom);
rc.max=v2i_lerp(src_rc.max,dst_rc.max, ti, denom);
sw_set_rect(&cw->mini,&rc);
}

void
clientwin_map(ClientWin *cw) {
session_t *ps = cw->mainwin->ps;
free_damage(ps, &cw->damage);

cw->damage = XDamageCreate(ps->dpy, cw->client.window, XDamageReportDeltaRectangles);
XRenderSetPictureTransform(ps->dpy, cw->origin, &cw->mainwin->transform);

// calculate transform for scaling..
XTransform transform;

transform.matrix[0][0] = XDoubleToFixed((float)cw->client.width/(float)cw->mini.width);
transform.matrix[0][1] = 0.0;
transform.matrix[0][2] = 0.0;
transform.matrix[1][0] = 0.0;
transform.matrix[1][1] = XDoubleToFixed((float)cw->client.height/(float)cw->mini.height);
transform.matrix[1][2] = 0.0;
transform.matrix[2][0] = 0.0;
transform.matrix[2][1] = 0.0;
transform.matrix[2][2] = XDoubleToFixed(1.0);

XRenderSetPictureTransform(ps->dpy, cw->origin, &transform);

// XRenderSetPictureTransform(ps->dpy, cw->origin, &cw->mainwin->transform);

clientwin_render(cw);

Expand Down Expand Up @@ -337,11 +381,13 @@ clientwin_unmap(ClientWin *cw)
static void
childwin_focus(ClientWin *cw)
{
XWarpPointer(cw->mainwin->ps->dpy, None, cw->client.window, 0, 0, 0, 0, cw->client.width / 2, cw->client.height / 2);
// how to handle it offscreen? need to map to screen coords, if its outside, do this warp in screen space
// if (!cw->mainwin->ps->o.xinerama_showAll)
XWarpPointer(cw->mainwin->ps->dpy, None, cw->client.window, 0, 0, 0, 0, sw_width(&cw->client) / 2, sw_height(&cw->client) / 2);
XRaiseWindow(cw->mainwin->ps->dpy, cw->client.window);
XSetInputFocus(cw->mainwin->ps->dpy, cw->client.window, RevertToParent, CurrentTime);
}

extern int g_redo_layout;
int
clientwin_handle(ClientWin *cw, XEvent *ev) {
session_t *ps = cw->mainwin->ps;
Expand Down Expand Up @@ -378,6 +424,14 @@ clientwin_handle(ClientWin *cw, XEvent *ev) {
|| ev->xkey.keycode == cw->mainwin->key_space) {
childwin_focus(cw);
return 1;
} else if (ev->xkey.keycode == cw->mainwin->key_page_up) {
ps->o.layout_grid^=true;
if (!(ps->o.layout_grid)) { ps->o.xinerama_showAll^=true;}
g_redo_layout=1;
} else if (ev->xkey.keycode == cw->mainwin->key_page_down) {
ps->o.layout_grid=true;
ps->o.xinerama_showAll=false;
g_redo_layout=1;
}
else
report_key_unbinded(ev);
Expand Down
65 changes: 64 additions & 1 deletion src/clientwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@
#ifndef SKIPPY_CLIENT_H
#define SKIPPY_CLIENT_H

//#define SW_POS_SIZE
typedef struct {
Window window;
#ifndef SW_POS_SIZE
int x, y;
unsigned int width, height;
#else
PosSize rect;
#endif
XRenderPictFormat *format;
} SkippyWindow;

Expand All @@ -41,7 +46,6 @@ typedef struct {
Pixmap pixmap;
Picture origin, destination;
Damage damage;
float factor;

int focused;

Expand All @@ -63,6 +67,9 @@ int clientwin_sort_func(dlist *, dlist *, void *);
ClientWin *clientwin_create(struct _MainWin *, Window);
void clientwin_destroy(ClientWin *, bool destroyed);
void clientwin_move(ClientWin *, float, int, int);
void clientwin_create_scaled_image(ClientWin *cw);
void clientwin_move_and_create_scaled_image(ClientWin *cw, float f, int dx, int dy);

void clientwin_map(ClientWin *);
void clientwin_unmap(ClientWin *);
int clientwin_handle(ClientWin *, XEvent *);
Expand All @@ -73,4 +80,60 @@ void clientwin_render(ClientWin *);
void clientwin_schedule_repair(ClientWin *cw, XRectangle *area);
void clientwin_repair(ClientWin *cw);

void
clientwin_lerp_client_to_mini(ClientWin* cw,float t);

// accessors, less needed if code is refactored to use vec2i etc.
// bloats the headers whilst the change is in progress, can be search-replaced when done
//
// abreviations:
//
// sw_ SkippyWindow
//
// cw_ ClientWindow
// mw_ MainWindow

#ifdef SW_POS_SIZE
inline Vec2i sw_pos(const SkippyWindow* w) { return w->rect.pos; }
inline Vec2i sw_size(const SkippyWindow* w) { return w->rect.size; }
inline void sw_set_pos(SkippyWindow* sw, const Vec2i p) { sw->rect.pos=p; }
inline void sw_set_size(SkippyWindow* sw, const Vec2i sz) { sw->rect.size=sz; }
inline void sw_set_rect(SkippyWindow* sw, const Rect2i* r) { sw_set_pos(sw,r->min); sw_set_size(sw, rect2i_size(r));}
inline int sw_width(const SkippyWindow* w) { return w->rect.size.x;} // => w->rect.size.x
inline int sw_height(const SkippyWindow* w) { return w->rect.size.y;} // => w->rect.size.y
inline int sw_x(const SkippyWindow* w) { return w->rect.pos.x;} // => w->rect.pos.x
inline int sw_y(const SkippyWindow* w) { return w->rect.pos.y;} // => w->rect.pos.y
#else
inline Vec2i sw_pos(const SkippyWindow* w) { return vec2i_mk(w->x,w->y); }
inline Vec2i sw_size(const SkippyWindow* w) { return vec2i_mk(w->width,w->height); }
inline void sw_set_pos(SkippyWindow* sw, const Vec2i p) { sw->x=p.x; sw->y=p.y; }
inline void sw_set_size(SkippyWindow* sw, const Vec2i sz) { sw->width=sz.x; sw->height=sz.y; }
inline void sw_set_rect(SkippyWindow* sw, const Rect2i* r) { sw_set_pos(sw,r->min); sw->width=r->max.x-r->min.x; sw->height=r->max.y-r->min.y;}
inline int sw_width(const SkippyWindow* w) { return w->width;} // => w->rect.size.x
inline int sw_height(const SkippyWindow* w) { return w->height;} // => w->rect.size.y
inline int sw_x(const SkippyWindow* w) { return w->x;} // => w->rect.pos.x
inline int sw_y(const SkippyWindow* w) { return w->y;} // => w->rect.pos.y
#endif
inline Vec2i sw_set_xy(SkippyWindow* sw,int x,int y) { sw_set_pos(sw,vec2i_mk(x,y)); }
inline Vec2i sw_set_width_height(SkippyWindow* sw,int w,int h) { sw_set_size(sw,vec2i_mk(w,h)); }
inline Rect2i sw_rect(const SkippyWindow* sw) { return rect2i_mk_at(sw_pos(sw),sw_size(sw));}
inline PosSize sw_pos_size(const SkippyWindow* sw) { return pos_size_mk(sw_pos(sw),sw_size(sw));}
inline void sw_set_pos_size(SkippyWindow* sw, const Vec2i p,const Vec2i sz) { sw_set_pos(sw,p); sw_set_size(sw,sz);}


inline Rect2i cw_client_rect(const ClientWin* w) { return rect2i_mk_at(sw_pos(&w->client),sw_size(&w->client));}
inline Rect2i cw_client_mini_rect(const ClientWin* w) { return rect2i_mk_at(sw_pos(&w->mini),sw_size(&w->mini));}
inline Vec2i cw_client_pos(const ClientWin* w) { return sw_pos(&w->client);}
inline Vec2i cw_client_size(const ClientWin* w) { return sw_size(&w->client);}
inline int cw_client_width(const ClientWin* w) { return sw_size(&w->client).x;}
inline int cw_client_height(const ClientWin* w) { return sw_size(&w->client).y;}
inline void cw_set_tmp_xy(ClientWin* w, int x, int y) { w->x = x; w->y=y;}
inline void cw_set_tmp_pos(ClientWin* w, Vec2i pos) { w->x = pos.x; w->y=pos.y;}
inline Vec2i cw_tmp_pos(ClientWin* w) { return vec2i_mk(w->x,w->y);}
inline float cw_client_aspect(const ClientWin* w) { Vec2i delta=sw_size(&w->client); return MAX(1,delta.x)/(float)MAX(1,delta.y);}
inline void cw_set_mini_size( ClientWin* w,Vec2i sz) { sw_set_size(&w->mini,sz);}
inline Vec2i cw_mini_centre(const ClientWin* cw) { return v2i_mad(sw_pos(&cw->mini), sw_size(&cw->mini), 1,2); }
inline Rect2i cw_mini_rect(const ClientWin* cw) { return sw_rect(&cw->mini); }
inline Vec2i cw_client_centre(const ClientWin* cw) { return v2i_mad(sw_pos(&cw->client), sw_size(&cw->client), 1,2); }
inline void cw_set_mini_rect(ClientWin* cw, const Rect2i* rc) { sw_set_rect(&cw->mini, rc);}
#endif /* SKIPPY_CLIENT_H */
39 changes: 39 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,44 @@ config_get_double_wrap(dlist *config, const char *section, const char *key,
*tgt = config_get_double(config, section, key, *tgt, min, max);
}

/**
* @brief Get a float value from configuration.
*/
static inline float
config_get_float(dlist *config, const char *section, const char *key,
float def, float min, float max) {
const char *result = config_get(config, section, key, NULL);
if (!result)
return def;
char *endptr = NULL;
float fresult = strtof(result, &endptr);
if (!endptr || (*endptr && !isspace(*endptr))) {
printfef("(%s, %s, %f): Value \"%s\" is not a valid floating-point number.",
section, key, def, result);
return def;
}
if (fresult > max) {
printfef("(%s, %s, %f): Value \"%s\" larger than maximum value %f.",
section, key, def, result, max);
return max;
}
if (fresult < min) {
printfef("(%s, %s, %f): Value \"%s\" smaller than minimal value %f.",
section, key, def, result, min);
return min;
}
return fresult;
}

/**
* @brief Wrapper of config_get_float().
*/
static inline void
config_get_float_wrap(dlist *config, const char *section, const char *key,
float *tgt, float min, float max) {
*tgt = config_get_float(config, section, key, *tgt, min, max);
}


#endif /* SKIPPY_CONFIG_H */

5 changes: 5 additions & 0 deletions src/dlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,9 @@ void dlist_swap(dlist *, dlist *);
typedef int (*dlist_cmp_func)(dlist *, dlist *, void *);
void dlist_sort(dlist *, dlist_cmp_func, void *);

/* Iteration helper macro */
#define DLIST_FOREACH(TYPE,ITER_PTR,IN_LIST) for (dlist* iter=IN_LIST; iter;iter=iter->next){ TYPE* ITER_PTR=(TYPE*)(iter->data);
#define DLIST_NEXT }


#endif /* SKIPPY_DLIST_H */
Loading