mirror of
https://github.com/LukeSmithxyz/st.git
synced 2024-11-22 07:15:59 +01:00
Move remaining selection mode logic into selextend
The "done" parameter indicates a change which finalizes the selection (e.g. a mouse button release as opposed to motion). Signed-off-by: Devin J. Pohly <djpohly@gmail.com>
This commit is contained in:
parent
bcb5d3adbe
commit
cfc7acdfd9
3 changed files with 22 additions and 22 deletions
14
st.c
14
st.c
|
@ -167,11 +167,11 @@ static ssize_t xwrite(int, const char *, size_t);
|
||||||
|
|
||||||
/* Globals */
|
/* Globals */
|
||||||
Term term;
|
Term term;
|
||||||
Selection sel;
|
|
||||||
int cmdfd;
|
int cmdfd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int oldbutton = 3; /* button event on startup: 3 = release */
|
int oldbutton = 3; /* button event on startup: 3 = release */
|
||||||
|
|
||||||
|
static Selection sel;
|
||||||
static CSIEscape csiescseq;
|
static CSIEscape csiescseq;
|
||||||
static STREscape strescseq;
|
static STREscape strescseq;
|
||||||
static int iofd = 1;
|
static int iofd = 1;
|
||||||
|
@ -402,9 +402,17 @@ selstart(int col, int row, int snap)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
selextend(int col, int row, int type)
|
selextend(int col, int row, int type, int done)
|
||||||
{
|
{
|
||||||
int oldey, oldex, oldsby, oldsey, oldtype;
|
int oldey, oldex, oldsby, oldsey, oldtype;
|
||||||
|
|
||||||
|
if (!sel.mode)
|
||||||
|
return;
|
||||||
|
if (done && sel.mode == SEL_EMPTY) {
|
||||||
|
selclear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
oldey = sel.oe.y;
|
oldey = sel.oe.y;
|
||||||
oldex = sel.oe.x;
|
oldex = sel.oe.x;
|
||||||
oldsby = sel.nb.y;
|
oldsby = sel.nb.y;
|
||||||
|
@ -419,6 +427,8 @@ selextend(int col, int row, int type)
|
||||||
|
|
||||||
if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type)
|
if (oldey != sel.oe.y || oldex != sel.oe.x || oldtype != sel.type)
|
||||||
tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
|
tsetdirt(MIN(sel.nb.y, oldsby), MAX(sel.ne.y, oldsey));
|
||||||
|
|
||||||
|
sel.mode = done ? SEL_IDLE : SEL_READY;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
3
st.h
3
st.h
|
@ -184,7 +184,7 @@ void resettitle(void);
|
||||||
void selclear(void);
|
void selclear(void);
|
||||||
void selinit(void);
|
void selinit(void);
|
||||||
void selstart(int, int, int);
|
void selstart(int, int, int);
|
||||||
void selextend(int, int, int);
|
void selextend(int, int, int, int);
|
||||||
void selnormalize(void);
|
void selnormalize(void);
|
||||||
int selected(int, int);
|
int selected(int, int);
|
||||||
char *getsel(void);
|
char *getsel(void);
|
||||||
|
@ -198,7 +198,6 @@ char *xstrdup(char *);
|
||||||
|
|
||||||
/* Globals */
|
/* Globals */
|
||||||
extern Term term;
|
extern Term term;
|
||||||
extern Selection sel;
|
|
||||||
extern int cmdfd;
|
extern int cmdfd;
|
||||||
extern pid_t pid;
|
extern pid_t pid;
|
||||||
extern int oldbutton;
|
extern int oldbutton;
|
||||||
|
|
27
x.c
27
x.c
|
@ -157,7 +157,7 @@ static void selnotify(XEvent *);
|
||||||
static void selclear_(XEvent *);
|
static void selclear_(XEvent *);
|
||||||
static void selrequest(XEvent *);
|
static void selrequest(XEvent *);
|
||||||
static void setsel(char *, Time);
|
static void setsel(char *, Time);
|
||||||
static void mousesel(XEvent *);
|
static void mousesel(XEvent *, int);
|
||||||
static void mousereport(XEvent *);
|
static void mousereport(XEvent *);
|
||||||
static char *kmap(KeySym, uint);
|
static char *kmap(KeySym, uint);
|
||||||
static int match(uint, uint);
|
static int match(uint, uint);
|
||||||
|
@ -313,7 +313,7 @@ y2row(int y)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mousesel(XEvent *e)
|
mousesel(XEvent *e, int done)
|
||||||
{
|
{
|
||||||
int type, seltype = SEL_REGULAR;
|
int type, seltype = SEL_REGULAR;
|
||||||
uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
|
uint state = e->xbutton.state & ~(Button1Mask | forceselmod);
|
||||||
|
@ -324,8 +324,9 @@ mousesel(XEvent *e)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
selextend(x2col(e->xbutton.x), y2row(e->xbutton.y), seltype, done);
|
||||||
selextend(x2col(e->xbutton.x), y2row(e->xbutton.y), seltype);
|
if (done)
|
||||||
|
setsel(getsel(), e->xbutton.time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -630,16 +631,10 @@ brelease(XEvent *e)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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 == SEL_READY) {
|
mousesel(e, 1);
|
||||||
mousesel(e);
|
|
||||||
setsel(getsel(), e->xbutton.time);
|
|
||||||
} else
|
|
||||||
selclear_(NULL);
|
|
||||||
sel.mode = SEL_IDLE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -650,11 +645,7 @@ bmotion(XEvent *e)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sel.mode)
|
mousesel(e, 0);
|
||||||
return;
|
|
||||||
|
|
||||||
sel.mode = SEL_READY;
|
|
||||||
mousesel(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue