Skip to content

Commit

Permalink
Merge pull request robm#8 from TheUnknownCylon/master
Browse files Browse the repository at this point in the history
Updated clickable areas (1 bugfix + clickable in slave window support)
  • Loading branch information
robm committed Dec 2, 2012
2 parents 982023f + fe6fa07 commit 5e512b7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 58 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ Interaction:
^ca(BTN, CMD) ... ^ca()

Used to define 'clickable areas' anywhere inside the
title window.
title window or slave window.
- 'BTN' denotes the mouse button (1=left, 2=right, 3=middle, etc.)
- 'CMD' denotes the command that should be spawned when the specific
area has been clicked with the defined button
Expand Down
89 changes: 47 additions & 42 deletions draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define MAX_ICON_CACHE 32

#define MAX(a,b) ((a)>(b)?(a):(b))
#define LNR2WINDOW(lnr) lnr==-1?0:1

typedef struct ICON_C {
char name[ARGLEN];
Expand All @@ -30,7 +31,9 @@ typedef struct ICON_C {
icon_c icons[MAX_ICON_CACHE];
int icon_cnt;
int otx;
int xorig=0;

int xorig[2];
sens_w window_sens[2];

/* command types for the in-text parser */
enum ctype {bg, fg, icon, rect, recto, circle, circleo, pos, abspos, titlewin, ibg, fn, fixpos, ca, ba};
Expand Down Expand Up @@ -419,17 +422,15 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
else {
h = dzen.font.height;
py = (dzen.line_height - h) / 2;
xorig = 0;


xorig[LNR2WINDOW(lnr)] = 0;

if(lnr != -1) {
pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.slave_win.width,
dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen));
}
else {
pm = XCreatePixmap(dzen.dpy, RootWindow(dzen.dpy, DefaultScreen(dzen.dpy)), dzen.title_win.width,
dzen.line_height, DefaultDepth(dzen.dpy, dzen.screen));
sens_areas_cnt = 0;
}

#ifdef DZEN_XFT
Expand Down Expand Up @@ -484,7 +485,7 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {

if( lnr != -1 && (lnr + dzen.slave_win.first_line_vis >= dzen.slave_win.tcnt)) {
XCopyArea(dzen.dpy, pm, dzen.slave_win.drawable[lnr], dzen.gc,
0, 0, px, dzen.line_height, xorig, 0);
0, 0, px, dzen.line_height, xorig[LNR2WINDOW(lnr)], 0);
XFreePixmap(dzen.dpy, pm);
return NULL;
}
Expand Down Expand Up @@ -732,30 +733,36 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
font_was_set = 1;
break;
case ca:
if(lnr == -1) {
if(tval[0]) {
if(sens_areas_cnt < MAX_CLICKABLE_AREAS) {
get_sens_area(tval,
&sens_areas[sens_areas_cnt].button,
sens_areas[sens_areas_cnt].cmd);
sens_areas[sens_areas_cnt].start_x = px;
sens_areas[sens_areas_cnt].start_y = py;
sens_areas[sens_areas_cnt].end_y = py;
max_y = py;
sens_areas[sens_areas_cnt].active = 0;
sens_areas_cnt++;
}
} else {
/* find most recent unclosed area */
for(i = sens_areas_cnt - 1; i >= 0; i--)
if(!sens_areas[i].active)
break;
if(i >= 0 && i < MAX_CLICKABLE_AREAS) {
sens_areas[i].end_x = px;
sens_areas[i].end_y = max_y;
sens_areas[i].active = 1;

; //nop to keep gcc happy
sens_w *w = &window_sens[LNR2WINDOW(lnr)];

if(tval[0]) {
click_a *area = &((*w).sens_areas[(*w).sens_areas_cnt]);
if((*w).sens_areas_cnt < MAX_CLICKABLE_AREAS) {
get_sens_area(tval,
&(*area).button,
(*area).cmd);
(*area).start_x = px;
(*area).start_y = py;
(*area).end_y = py;
max_y = py;
(*area).active = 0;
if(lnr == -1) {
(*area).win = dzen.title_win.win;
} else {
(*area).win = dzen.slave_win.line[lnr];
}
(*w).sens_areas_cnt++;
}
} else {
//find most recent unclosed area
for(i = (*w).sens_areas_cnt - 1; i >= 0; i--)
if(!(*w).sens_areas[i].active)
break;
if(i >= 0 && i < MAX_CLICKABLE_AREAS) {
(*w).sens_areas[i].end_x = px;
(*w).sens_areas[i].end_y = max_y;
(*w).sens_areas[i].active = 1;
}
}
break;
Expand Down Expand Up @@ -871,14 +878,14 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {

} else {
if(align == ALIGNLEFT)
xorig = 0;
xorig[LNR2WINDOW(lnr)] = 0;
if(align == ALIGNCENTER) {
xorig = (lnr != -1) ?
xorig[LNR2WINDOW(lnr)] = (lnr != -1) ?
(dzen.slave_win.width - px)/2 :
(dzen.title_win.width - px)/2;
}
else if(align == ALIGNRIGHT) {
xorig = (lnr != -1) ?
xorig[LNR2WINDOW(lnr)] = (lnr != -1) ?
(dzen.slave_win.width - px) :
(dzen.title_win.width - px);
}
Expand All @@ -887,11 +894,11 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {

if(lnr != -1) {
XCopyArea(dzen.dpy, pm, dzen.slave_win.drawable[lnr], dzen.gc,
0, 0, dzen.w, dzen.line_height, xorig, 0);
0, 0, dzen.w, dzen.line_height, xorig[LNR2WINDOW(lnr)], 0);
}
else {
XCopyArea(dzen.dpy, pm, dzen.title_win.drawable, dzen.gc,
0, 0, dzen.w, dzen.line_height, xorig, 0);
0, 0, dzen.w, dzen.line_height, xorig[LNR2WINDOW(lnr)], 0);
}
XFreePixmap(dzen.dpy, pm);

Expand Down Expand Up @@ -994,7 +1001,9 @@ drawheader(const char * text) {
if (text){
dzen.w = dzen.title_win.width;
dzen.h = dzen.line_height;


window_sens[TOPWINDOW].sens_areas_cnt = 0;

XFillRectangle(dzen.dpy, dzen.title_win.drawable, dzen.rgc, 0, 0, dzen.w, dzen.h);
parse_line(text, -1, dzen.title_win.alignment, 0, 0);
}
Expand All @@ -1011,21 +1020,17 @@ void
drawbody(char * text) {
char *ec;
int i, write_buffer=1;


if(dzen.slave_win.tcnt == -1) {
dzen.slave_win.tcnt = 0;
drawheader(text);
return;
}


if((ec = strstr(text, "^tw()")) && (*(ec-1) != '^')) {
dzen.w = dzen.title_win.width;
dzen.h = dzen.line_height;

XFillRectangle(dzen.dpy, dzen.title_win.drawable, dzen.rgc, 0, 0, dzen.w, dzen.h);
parse_line(ec+5, -1, dzen.title_win.alignment, 0, 0);
XCopyArea(dzen.dpy, dzen.title_win.drawable, dzen.title_win.win,
dzen.gc, 0, 0, dzen.w, dzen.h, 0, 0);
drawheader(ec+5);
return;
}

Expand Down
16 changes: 13 additions & 3 deletions dzen.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#define ALIGNLEFT 1
#define ALIGNRIGHT 2

#define TOPWINDOW 0
#define SLAVEWINDOW 1

#define MIN_BUF_SIZE 1024
#define MAX_LINE_LEN 8192

Expand Down Expand Up @@ -68,11 +71,18 @@ typedef struct _CLICK_A {
int end_x;
int start_y;
int end_y;
Window win; //(line)window to which the action is attached
char cmd[1024];
} click_a;
extern click_a sens_areas[MAX_CLICKABLE_AREAS];
extern int sens_areas_cnt;
extern int xorig;

typedef struct _SENS_PER_WINDOW {
click_a sens_areas[MAX_CLICKABLE_AREAS];
int sens_areas_cnt;
} sens_w;

//0: top window, 1: slave window
extern int xorig[2];
extern sens_w window_sens[2];


/* title window */
Expand Down
25 changes: 13 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
Dzen dzen = {0};
static int last_cnt = 0;
typedef void sigfunc(int);
click_a sens_areas[MAX_CLICKABLE_AREAS];
int sens_areas_cnt=0;


static void
clean_up(void) {
Expand Down Expand Up @@ -196,6 +193,8 @@ x_draw_body(void) {
dzen.y = 0;
dzen.w = dzen.slave_win.width;
dzen.h = dzen.line_height;

window_sens[SLAVEWINDOW].sens_areas_cnt = 0;

if(!dzen.slave_win.last_line_vis) {
if(dzen.slave_win.tcnt < dzen.slave_win.max_lines) {
Expand Down Expand Up @@ -702,15 +701,17 @@ handle_xev(void) {
}

/* clickable areas */
for(i=sens_areas_cnt; i>=0; i--) {
if(ev.xbutton.window == dzen.title_win.win &&
ev.xbutton.button == sens_areas[i].button &&
(ev.xbutton.x >= sens_areas[i].start_x+xorig &&
ev.xbutton.x <= sens_areas[i].end_x+xorig) &&
(ev.xbutton.y >= sens_areas[i].start_y &&
ev.xbutton.y <= sens_areas[i].end_y) &&
sens_areas[i].active) {
spawn(sens_areas[i].cmd);
int w_id = ev.xbutton.window == dzen.title_win.win ? 0 : 1;
sens_w w = window_sens[w_id];
for(i=w.sens_areas_cnt; i>=0; i--) {
if(ev.xbutton.window == w.sens_areas[i].win &&
ev.xbutton.button == w.sens_areas[i].button &&
(ev.xbutton.x >= w.sens_areas[i].start_x+xorig[w_id] &&
ev.xbutton.x <= w.sens_areas[i].end_x+xorig[w_id]) &&
(ev.xbutton.y >= w.sens_areas[i].start_y &&
ev.xbutton.y <= w.sens_areas[i].end_y) &&
w.sens_areas[i].active) {
spawn(w.sens_areas[i].cmd);
sa_clicked++;
break;
}
Expand Down

0 comments on commit 5e512b7

Please sign in to comment.