@ -15,6 +15,7 @@
# include <X11/extensions/Xinerama.h>
# include <X11/extensions/Xinerama.h>
# endif
# endif
# include <X11/Xft/Xft.h>
# include <X11/Xft/Xft.h>
# include <X11/XF86keysym.h>
# include "drw.h"
# include "drw.h"
# include "util.h"
# include "util.h"
@ -444,6 +445,7 @@ insert:
if ( lines > 0 )
if ( lines > 0 )
return ;
return ;
/* fallthrough */
/* fallthrough */
case XF86XK_AudioRaiseVolume :
case XK_Up :
case XK_Up :
if ( sel & & sel - > left & & ( sel = sel - > left ) - > right = = curr ) {
if ( sel & & sel - > left & & ( sel = sel - > left ) - > right = = curr ) {
curr = prev ;
curr = prev ;
@ -462,6 +464,7 @@ insert:
sel = curr = prev ;
sel = curr = prev ;
calcoffsets ( ) ;
calcoffsets ( ) ;
break ;
break ;
case XF86XK_PowerOff :
case XK_Return :
case XK_Return :
case XK_KP_Enter :
case XK_KP_Enter :
puts ( ( sel & & ! ( ev - > state & ShiftMask ) ) ? sel - > text : text ) ;
puts ( ( sel & & ! ( ev - > state & ShiftMask ) ) ? sel - > text : text ) ;
@ -480,6 +483,7 @@ insert:
if ( lines > 0 )
if ( lines > 0 )
return ;
return ;
/* fallthrough */
/* fallthrough */
case XF86XK_AudioLowerVolume :
case XK_Down :
case XK_Down :
if ( sel & & sel - > right & & ( sel = sel - > right ) = = next ) {
if ( sel & & sel - > right & & ( sel = sel - > right ) = = next ) {
curr = next ;
curr = next ;
@ -500,6 +504,119 @@ draw:
drawmenu ( ) ;
drawmenu ( ) ;
}
}
static void
buttonpress ( XEvent * e )
{
struct item * item ;
XButtonPressedEvent * ev = & e - > xbutton ;
int x = 0 , y = 0 , h = bh , w ;
if ( ev - > window ! = win )
return ;
/* right-click: exit */
if ( ev - > button = = Button3 )
exit ( 1 ) ;
if ( prompt & & * prompt )
x + = promptw ;
/* input field */
w = ( lines > 0 | | ! matches ) ? mw - x : inputw ;
/* left-click on input: clear input,
* NOTE : if there is no left - arrow the space for < is reserved so
* add that to the input width */
if ( ev - > button = = Button1 & &
( ( lines < = 0 & & ev - > x > = 0 & & ev - > x < = x + w +
( ( ! prev | | ! curr - > left ) ? TEXTW ( " < " ) : 0 ) ) | |
( lines > 0 & & ev - > y > = y & & ev - > y < = y + h ) ) ) {
insert ( NULL , - cursor ) ;
drawmenu ( ) ;
return ;
}
/* middle-mouse click: paste selection */
if ( ev - > button = = Button2 ) {
XConvertSelection ( dpy , ( ev - > state & ShiftMask ) ? clip : XA_PRIMARY ,
utf8 , utf8 , win , CurrentTime ) ;
drawmenu ( ) ;
return ;
}
/* scroll up */
if ( ev - > button = = Button4 & & prev ) {
sel = curr = prev ;
calcoffsets ( ) ;
drawmenu ( ) ;
return ;
}
/* scroll down */
if ( ev - > button = = Button5 & & next ) {
sel = curr = next ;
calcoffsets ( ) ;
drawmenu ( ) ;
return ;
}
if ( ev - > button ! = Button1 )
return ;
//if (ev->state & ~ControlMask)
// return;
if ( lines > 0 ) {
/* vertical list: (ctrl)left-click on item */
w = mw - x ;
for ( item = curr ; item ! = next ; item = item - > right ) {
y + = h ;
if ( ev - > y > = y & & ev - > y < = ( y + h ) ) {
puts ( item - > text ) ;
if ( ! ( ev - > state & ControlMask ) )
exit ( 0 ) ;
sel = item ;
if ( sel ) {
sel - > out = 1 ;
drawmenu ( ) ;
}
return ;
}
}
} else if ( matches ) {
/* left-click on left arrow */
x + = inputw ;
w = TEXTW ( " < " ) ;
if ( prev & & curr - > left ) {
if ( ev - > x > = x & & ev - > x < = x + w ) {
sel = curr = prev ;
calcoffsets ( ) ;
drawmenu ( ) ;
return ;
}
}
/* horizontal list: (ctrl)left-click on item */
for ( item = curr ; item ! = next ; item = item - > right ) {
x + = w ;
w = MIN ( TEXTW ( item - > text ) , mw - x - TEXTW ( " > " ) ) ;
if ( ev - > x > = x & & ev - > x < = x + w ) {
puts ( item - > text ) ;
if ( ! ( ev - > state & ControlMask ) )
exit ( 0 ) ;
sel = item ;
if ( sel ) {
sel - > out = 1 ;
drawmenu ( ) ;
}
return ;
}
}
/* left-click on right arrow */
w = TEXTW ( " > " ) ;
x = mw - w ;
if ( next & & ev - > x > = x & & ev - > x < = x + w ) {
sel = curr = next ;
calcoffsets ( ) ;
drawmenu ( ) ;
return ;
}
}
}
static void
static void
paste ( void )
paste ( void )
{
{
@ -561,6 +678,9 @@ run(void)
break ;
break ;
cleanup ( ) ;
cleanup ( ) ;
exit ( 1 ) ;
exit ( 1 ) ;
case ButtonPress :
buttonpress ( & ev ) ;
break ;
case Expose :
case Expose :
if ( ev . xexpose . count = = 0 )
if ( ev . xexpose . count = = 0 )
drw_map ( drw , win , 0 , 0 , mw , mh ) ;
drw_map ( drw , win , 0 , 0 , mw , mh ) ;
@ -658,7 +778,8 @@ setup(void)
/* create menu window */
/* create menu window */
swa . override_redirect = True ;
swa . override_redirect = True ;
swa . background_pixel = scheme [ SchemeNorm ] [ ColBg ] . pixel ;
swa . background_pixel = scheme [ SchemeNorm ] [ ColBg ] . pixel ;
swa . event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask ;
swa . event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask |
ButtonPressMask ;
win = XCreateWindow ( dpy , parentwin , x , y , mw , mh , 0 ,
win = XCreateWindow ( dpy , parentwin , x , y , mw , mh , 0 ,
CopyFromParent , CopyFromParent , CopyFromParent ,
CopyFromParent , CopyFromParent , CopyFromParent ,
CWOverrideRedirect | CWBackPixel | CWEventMask , & swa ) ;
CWOverrideRedirect | CWBackPixel | CWEventMask , & swa ) ;