Permalink
Browse files

Clickable areas support in the slave window as well (this also fixed …

…the sometimes no click operation).
  • Loading branch information...
1 parent ec38ea6 commit fe6fa07d798acdbd1321254463119db78fe1a611 @TheUnknownCylon TheUnknownCylon committed Dec 1, 2012
Showing with 54 additions and 45 deletions.
  1. +1 −1 README
  2. +28 −27 draw.c
  3. +12 −4 dzen.h
  4. +13 −13 main.c
View
2 README
@@ -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
View
55 draw.c
@@ -31,7 +31,9 @@ typedef struct ICON_C {
icon_c icons[MAX_ICON_CACHE];
int icon_cnt;
int otx;
-int xorig[2]; //0: topwindow, 1: slave window
+
+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};
@@ -731,34 +733,36 @@ parse_line(const char *line, int lnr, int align, int reverse, int nodraw) {
font_was_set = 1;
break;
case ca:
+ ; //nop to keep gcc happy
+ sens_w *w = &window_sens[LNR2WINDOW(lnr)];
+
if(tval[0]) {
- if(sens_areas_cnt < MAX_CLICKABLE_AREAS) {
+ click_a *area = &((*w).sens_areas[(*w).sens_areas_cnt]);
+ if((*w).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;
+ &(*area).button,
+ (*area).cmd);
+ (*area).start_x = px;
+ (*area).start_y = py;
+ (*area).end_y = py;
max_y = py;
- sens_areas[sens_areas_cnt].topslave = LNR2WINDOW(lnr);
- sens_areas[sens_areas_cnt].active = 0;
+ (*area).active = 0;
if(lnr == -1) {
- sens_areas[sens_areas_cnt].win = dzen.title_win.win;
+ (*area).win = dzen.title_win.win;
} else {
- sens_areas[sens_areas_cnt].win = dzen.slave_win.line[lnr];
+ (*area).win = dzen.slave_win.line[lnr];
}
- sens_areas_cnt++;
-
+ (*w).sens_areas_cnt++;
}
} else {
- /* find most recent unclosed area */
- for(i = sens_areas_cnt - 1; i >= 0; i--)
- if(!sens_areas[i].active)
+ //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) {
- sens_areas[i].end_x = px;
- sens_areas[i].end_y = max_y;
- sens_areas[i].active = 1;
+ (*w).sens_areas[i].end_x = px;
+ (*w).sens_areas[i].end_y = max_y;
+ (*w).sens_areas[i].active = 1;
}
}
break;
@@ -997,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);
}
@@ -1022,14 +1028,9 @@ drawbody(char * 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;
}
View
16 dzen.h
@@ -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
@@ -68,13 +71,18 @@ typedef struct _CLICK_A {
int end_x;
int start_y;
int end_y;
- int topslave;
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[2]; //0: top window, 1: slave window
+
+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 */
View
26 main.c
@@ -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) {
@@ -158,7 +155,6 @@ read_stdin(void) {
}
else {
while((n_off = chomp(buf, retbuf, n_off, n))) {
- sens_areas_cnt = 0;
if(!dzen.slave_win.ishmenu
&& dzen.tsupdate
&& dzen.slave_win.max_lines
@@ -197,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) {
@@ -703,15 +701,17 @@ handle_xev(void) {
}
/* clickable areas */
- for(i=sens_areas_cnt; i>=0; i--) {
- if(ev.xbutton.window == sens_areas[i].win &&
- ev.xbutton.button == sens_areas[i].button &&
- (ev.xbutton.x >= sens_areas[i].start_x+xorig[sens_areas[i].topslave] &&
- ev.xbutton.x <= sens_areas[i].end_x+xorig[sens_areas[i].topslave]) &&
- (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;
}

0 comments on commit fe6fa07

Please sign in to comment.