mirror of
https://github.com/davatorium/rofi.git
synced 2025-01-27 15:25:24 -05:00
Use accessors in RofiView to get modi's and num modi for sidebar.
This commit is contained in:
parent
3b007b7eff
commit
11c347fad8
4 changed files with 37 additions and 13 deletions
|
@ -19,6 +19,22 @@
|
||||||
*/
|
*/
|
||||||
extern const char *cache_dir;
|
extern const char *cache_dir;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the number of enabled modi.
|
||||||
|
*
|
||||||
|
* @returns the number of enabled modi.
|
||||||
|
*/
|
||||||
|
unsigned int rofi_get_num_enabled_modi ( void );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param index The mode to return. (should be smaller then rofi_get_num_enabled_mode)
|
||||||
|
*
|
||||||
|
* Get an enabled mode handle.
|
||||||
|
*
|
||||||
|
* @returns a Mode handle.
|
||||||
|
*/
|
||||||
|
const Mode * rofi_get_mode ( unsigned int index );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param key the Key to match
|
* @param key the Key to match
|
||||||
* @param modstate the modifier state to match
|
* @param modstate the modifier state to match
|
||||||
|
|
|
@ -63,7 +63,7 @@ typedef struct RofiViewState
|
||||||
workarea mon;
|
workarea mon;
|
||||||
|
|
||||||
// Sidebar view
|
// Sidebar view
|
||||||
ssize_t num_modi;
|
unsigned int num_modi;
|
||||||
textbox **modi;
|
textbox **modi;
|
||||||
|
|
||||||
MenuFlags menu_flags;
|
MenuFlags menu_flags;
|
||||||
|
|
|
@ -83,6 +83,16 @@ gboolean quiet = FALSE;
|
||||||
static void process_result ( RofiViewState *state );
|
static void process_result ( RofiViewState *state );
|
||||||
gboolean main_loop_x11_event_handler ( G_GNUC_UNUSED gpointer data );
|
gboolean main_loop_x11_event_handler ( G_GNUC_UNUSED gpointer data );
|
||||||
|
|
||||||
|
unsigned int rofi_get_num_enabled_modi ( void )
|
||||||
|
{
|
||||||
|
return num_modi;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Mode * rofi_get_mode ( unsigned int index )
|
||||||
|
{
|
||||||
|
return modi[index];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param name Name of the switcher to lookup.
|
* @param name Name of the switcher to lookup.
|
||||||
*
|
*
|
||||||
|
|
|
@ -66,10 +66,6 @@
|
||||||
#include "view.h"
|
#include "view.h"
|
||||||
#include "view-internal.h"
|
#include "view-internal.h"
|
||||||
|
|
||||||
// TODO get rid of num_modi and modi, use an accessor.
|
|
||||||
extern unsigned int num_modi;
|
|
||||||
extern Mode **modi;
|
|
||||||
|
|
||||||
// What todo with these.
|
// What todo with these.
|
||||||
extern Display *display;
|
extern Display *display;
|
||||||
extern SnLauncheeContext *sncontext;
|
extern SnLauncheeContext *sncontext;
|
||||||
|
@ -826,7 +822,7 @@ void rofi_view_update ( RofiViewState *state )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( config.sidebar_mode == TRUE ) {
|
if ( config.sidebar_mode == TRUE ) {
|
||||||
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
for ( unsigned int j = 0; j < state->num_modi; j++ ) {
|
||||||
if ( state->modi[j] != NULL ) {
|
if ( state->modi[j] != NULL ) {
|
||||||
textbox_draw ( state->modi[j], d );
|
textbox_draw ( state->modi[j], d );
|
||||||
}
|
}
|
||||||
|
@ -879,8 +875,8 @@ static void rofi_view_resize ( RofiViewState *state )
|
||||||
unsigned int sbw = config.line_margin + 8;
|
unsigned int sbw = config.line_margin + 8;
|
||||||
widget_move ( WIDGET ( state->scrollbar ), state->w - state->border - sbw, state->top_offset );
|
widget_move ( WIDGET ( state->scrollbar ), state->w - state->border - sbw, state->top_offset );
|
||||||
if ( config.sidebar_mode == TRUE ) {
|
if ( config.sidebar_mode == TRUE ) {
|
||||||
int width = ( state->w - ( 2 * ( state->border ) + ( num_modi - 1 ) * config.line_margin ) ) / num_modi;
|
int width = ( state->w - ( 2 * ( state->border ) + ( state->num_modi - 1 ) * config.line_margin ) ) / state->num_modi;
|
||||||
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
for ( unsigned int j = 0; j < state->num_modi; j++ ) {
|
||||||
textbox_moveresize ( state->modi[j],
|
textbox_moveresize ( state->modi[j],
|
||||||
state->border + j * ( width + config.line_margin ), state->h - state->line_height - state->border,
|
state->border + j * ( width + config.line_margin ), state->h - state->line_height - state->border,
|
||||||
width, state->line_height );
|
width, state->line_height );
|
||||||
|
@ -1041,7 +1037,7 @@ static void rofi_view_mouse_navigation ( RofiViewState *state, XButtonEvent *xbe
|
||||||
state->update = TRUE;
|
state->update = TRUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for ( unsigned int i = 0; config.sidebar_mode == TRUE && i < num_modi; i++ ) {
|
for ( unsigned int i = 0; config.sidebar_mode == TRUE && i < state->num_modi; i++ ) {
|
||||||
if ( widget_intersect ( &( state->modi[i]->widget ), xbe->x, xbe->y ) ) {
|
if ( widget_intersect ( &( state->modi[i]->widget ), xbe->x, xbe->y ) ) {
|
||||||
( state->selected_line ) = 0;
|
( state->selected_line ) = 0;
|
||||||
state->retv = MENU_QUICK_SWITCH | ( i & MENU_LOWER_MASK );
|
state->retv = MENU_QUICK_SWITCH | ( i & MENU_LOWER_MASK );
|
||||||
|
@ -1563,12 +1559,14 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
||||||
calculate_window_position ( state );
|
calculate_window_position ( state );
|
||||||
|
|
||||||
if ( config.sidebar_mode == TRUE ) {
|
if ( config.sidebar_mode == TRUE ) {
|
||||||
int width = ( state->w - ( 2 * ( state->border ) + ( num_modi - 1 ) * config.line_margin ) ) / num_modi;
|
state->num_modi = rofi_get_num_enabled_modi ();
|
||||||
state->modi = g_malloc0 ( num_modi * sizeof ( textbox * ) );
|
int width = ( state->w - ( 2 * ( state->border ) + ( state->num_modi - 1 ) * config.line_margin ) ) / state->num_modi;
|
||||||
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) );
|
||||||
|
for ( unsigned int j = 0; j < state->num_modi; j++ ) {
|
||||||
|
const Mode * mode = rofi_get_mode ( j );
|
||||||
state->modi[j] = textbox_create ( TB_CENTER, state->border + j * ( width + config.line_margin ),
|
state->modi[j] = textbox_create ( TB_CENTER, state->border + j * ( width + config.line_margin ),
|
||||||
state->h - state->line_height - state->border, width, state->line_height,
|
state->h - state->line_height - state->border, width, state->line_height,
|
||||||
( modi[j] == state->sw ) ? HIGHLIGHT : NORMAL, mode_get_name ( modi[j] ) );
|
( mode == state->sw ) ? HIGHLIGHT : NORMAL, mode_get_name ( mode ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue