mirror of
https://github.com/davatorium/rofi.git
synced 2025-01-27 15:25:24 -05:00
scrollbar: Handle mouse clicks, fix width, remove border.
This commit is contained in:
parent
d3481de3d6
commit
380697b895
3 changed files with 20 additions and 7 deletions
|
@ -21,4 +21,5 @@ void scrollbar_set_pos_length ( scrollbar *sb, unsigned int pos_length );
|
|||
void scrollbar_set_pos ( scrollbar *sb, unsigned int pos );
|
||||
void scrollbar_set_length ( scrollbar *sb, unsigned int length );
|
||||
void scrollbar_draw ( scrollbar *sb );
|
||||
unsigned int scrollbar_clicked ( scrollbar *sb, int y );
|
||||
#endif // ROFI_SCROLLBAR_H
|
||||
|
|
|
@ -662,6 +662,11 @@ static void menu_mouse_navigation ( MenuState *state, XButtonEvent *xbe )
|
|||
return;
|
||||
}
|
||||
else {
|
||||
if ( state->scrollbar && state->scrollbar->window == xbe->window ) {
|
||||
state->selected = scrollbar_clicked ( state->scrollbar, xbe->y );
|
||||
state->update = TRUE;
|
||||
return;
|
||||
}
|
||||
for ( unsigned int i = 0; config.sidebar_mode == TRUE && i < num_switchers; i++ ) {
|
||||
if ( switchers[i]->tb->window == ( xbe->window ) ) {
|
||||
*( state->selected_line ) = 0;
|
||||
|
@ -1017,8 +1022,8 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom
|
|||
x_offset, y_offset,
|
||||
state.element_width, element_height, NORMAL, "" );
|
||||
}
|
||||
state.scrollbar = scrollbar_create ( main_window, &vinfo, map, state.w - config.padding - 10, state.top_offset,
|
||||
10, ( state.max_rows - 1 ) * ( element_height + config.line_margin ) + element_height - 2 );
|
||||
state.scrollbar = scrollbar_create ( main_window, &vinfo, map, state.w - config.padding - 8, state.top_offset,
|
||||
8, ( state.max_rows - 1 ) * ( element_height + config.line_margin ) + element_height );
|
||||
|
||||
|
||||
scrollbar_set_length ( state.scrollbar, state.num_lines );
|
||||
|
|
|
@ -37,8 +37,6 @@
|
|||
|
||||
extern Display *display;
|
||||
|
||||
#define SCROLLBAR_WIDTH 10
|
||||
|
||||
scrollbar *scrollbar_create ( Window parent, XVisualInfo *vinfo, Colormap map,
|
||||
short x, short y, short w, short h )
|
||||
{
|
||||
|
@ -50,7 +48,7 @@ scrollbar *scrollbar_create ( Window parent, XVisualInfo *vinfo, Colormap map,
|
|||
sb->w = MAX ( 1, w );
|
||||
sb->h = MAX ( 1, h );
|
||||
|
||||
sb->length = SCROLLBAR_WIDTH;
|
||||
sb->length = 10;
|
||||
sb->pos = 0;
|
||||
sb->pos_length = 4;
|
||||
|
||||
|
@ -58,9 +56,10 @@ scrollbar *scrollbar_create ( Window parent, XVisualInfo *vinfo, Colormap map,
|
|||
attr.colormap = map;
|
||||
attr.border_pixel = color_border ( display );
|
||||
attr.background_pixel = color_background ( display );
|
||||
sb->window = XCreateWindow ( display, sb->parent, sb->x, sb->y, sb->w, sb->h, 1, vinfo->depth,
|
||||
sb->window = XCreateWindow ( display, sb->parent, sb->x, sb->y, sb->w, sb->h, 0, vinfo->depth,
|
||||
InputOutput, vinfo->visual, CWColormap | CWBorderPixel | CWBackPixel, &attr );
|
||||
|
||||
XSelectInput ( display, sb->window, ExposureMask | ButtonPressMask );
|
||||
sb->gc = XCreateGC ( display, sb->window, 0, 0 );
|
||||
XSetForeground ( display, sb->gc, color_separator ( display ) );
|
||||
//XSetFillStyle ( display, sb->gc, FillSolid);
|
||||
|
@ -116,5 +115,13 @@ void scrollbar_draw ( scrollbar *sb )
|
|||
// Redraw base window
|
||||
XClearWindow ( display, sb->window );
|
||||
// Paint the handle.
|
||||
XFillRectangle ( display, sb->window, sb->gc, 1, y, SCROLLBAR_WIDTH - 2, height );
|
||||
XFillRectangle ( display, sb->window, sb->gc, 1, y, sb->w, height );
|
||||
}
|
||||
|
||||
unsigned int scrollbar_clicked ( scrollbar *sb, int y )
|
||||
{
|
||||
const short bh = sb->h - 2;
|
||||
float sec = ( ( bh ) / (float) sb->length );
|
||||
unsigned int sel = y / sec;
|
||||
return sel;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue