Browse Source

Add enumeration for sel.mode

This patch also prevents sel.mode from increasing beyond 2. It is almost
impossible, but sel.mode may overflow if mouse is moved around for too
long while selecting.
master
noname 10 years ago
committed by Roberto E. Vargas Caballero
parent
commit
1811b6030c
1 changed files with 14 additions and 9 deletions
  1. +14
    -9
      st.c

+ 14
- 9
st.c View File

@ -162,6 +162,12 @@ enum window_state {
WIN_FOCUSED = 2 WIN_FOCUSED = 2
}; };
enum selection_mode {
SEL_IDLE = 0,
SEL_EMPTY = 1,
SEL_READY = 2
};
enum selection_type { enum selection_type {
SEL_REGULAR = 1, SEL_REGULAR = 1,
SEL_RECTANGULAR = 2 SEL_RECTANGULAR = 2
@ -643,7 +649,7 @@ void
selinit(void) { selinit(void) {
memset(&sel.tclick1, 0, sizeof(sel.tclick1)); memset(&sel.tclick1, 0, sizeof(sel.tclick1));
memset(&sel.tclick2, 0, sizeof(sel.tclick2)); memset(&sel.tclick2, 0, sizeof(sel.tclick2));
sel.mode = 0;
sel.mode = SEL_IDLE;
sel.ob.x = -1; sel.ob.x = -1;
sel.primary = NULL; sel.primary = NULL;
sel.clipboard = NULL; sel.clipboard = NULL;
@ -897,7 +903,7 @@ bpress(XEvent *e) {
/* Clear previous selection, logically and visually. */ /* Clear previous selection, logically and visually. */
selclear(NULL); selclear(NULL);
sel.mode = 1;
sel.mode = SEL_EMPTY;
sel.type = SEL_REGULAR; sel.type = SEL_REGULAR;
sel.oe.x = sel.ob.x = x2col(e->xbutton.x); sel.oe.x = sel.ob.x = x2col(e->xbutton.x);
sel.oe.y = sel.ob.y = y2row(e->xbutton.y); sel.oe.y = sel.ob.y = y2row(e->xbutton.y);
@ -920,7 +926,7 @@ bpress(XEvent *e) {
* make clicks visible * make clicks visible
*/ */
if(sel.snap != 0) { if(sel.snap != 0) {
sel.mode++;
sel.mode = SEL_READY;
tsetdirt(sel.nb.y, sel.ne.y); tsetdirt(sel.nb.y, sel.ne.y);
} }
sel.tclick2 = sel.tclick1; sel.tclick2 = sel.tclick1;
@ -1142,13 +1148,12 @@ brelease(XEvent *e) {
if(e->xbutton.button == Button2) { if(e->xbutton.button == Button2) {
selpaste(NULL); selpaste(NULL);
} else if(e->xbutton.button == Button1) { } else if(e->xbutton.button == Button1) {
if(sel.mode < 2) {
selclear(NULL);
} else {
if(sel.mode == SEL_READY) {
getbuttoninfo(e); getbuttoninfo(e);
selcopy(e->xbutton.time); selcopy(e->xbutton.time);
}
sel.mode = 0;
} else
selclear(NULL);
sel.mode = SEL_IDLE;
tsetdirt(sel.nb.y, sel.ne.y); tsetdirt(sel.nb.y, sel.ne.y);
} }
} }
@ -1165,7 +1170,7 @@ bmotion(XEvent *e) {
if(!sel.mode) if(!sel.mode)
return; return;
sel.mode++;
sel.mode = SEL_READY;
oldey = sel.oe.y; oldey = sel.oe.y;
oldex = sel.oe.x; oldex = sel.oe.x;
oldsby = sel.nb.y; oldsby = sel.nb.y;


Loading…
Cancel
Save