mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Use snprintf instead of sprintf
This commit is contained in:
parent
d7dab65e5b
commit
c6a9de8c4a
7 changed files with 32 additions and 34 deletions
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
typedef struct _scrollbar
|
||||
{
|
||||
Widget widget;
|
||||
Widget widget;
|
||||
unsigned int length;
|
||||
unsigned int pos;
|
||||
unsigned int pos_length;
|
||||
|
|
|
@ -40,14 +40,14 @@ typedef struct
|
|||
|
||||
typedef enum
|
||||
{
|
||||
TB_AUTOHEIGHT = 1 << 0,
|
||||
TB_AUTOWIDTH = 1 << 1,
|
||||
TB_LEFT = 1 << 16,
|
||||
TB_RIGHT = 1 << 17,
|
||||
TB_CENTER = 1 << 18,
|
||||
TB_EDITABLE = 1 << 19,
|
||||
TB_MARKUP = 1 << 20,
|
||||
TB_WRAP = 1 << 21,
|
||||
TB_AUTOHEIGHT = 1 << 0,
|
||||
TB_AUTOWIDTH = 1 << 1,
|
||||
TB_LEFT = 1 << 16,
|
||||
TB_RIGHT = 1 << 17,
|
||||
TB_CENTER = 1 << 18,
|
||||
TB_EDITABLE = 1 << 19,
|
||||
TB_MARKUP = 1 << 20,
|
||||
TB_WRAP = 1 << 21,
|
||||
} TextboxFlags;
|
||||
|
||||
typedef enum
|
||||
|
|
|
@ -21,7 +21,7 @@ typedef struct _Widget
|
|||
} Widget;
|
||||
|
||||
/** Macro to get widget from an implementation (e.g. textbox/scrollbar) */
|
||||
#define WIDGET(a) (a != NULL?&(a->widget):NULL)
|
||||
#define WIDGET( a ) ( a != NULL ? &( a->widget ) : NULL )
|
||||
|
||||
/**
|
||||
* @param widget The widget to check
|
||||
|
@ -32,7 +32,7 @@ typedef struct _Widget
|
|||
*
|
||||
* @return TRUE if x,y falls within the widget
|
||||
*/
|
||||
int widget_intersect ( const Widget *widget, int x, int y);
|
||||
int widget_intersect ( const Widget *widget, int x, int y );
|
||||
|
||||
/**
|
||||
* @param widget The widget to move
|
||||
|
@ -41,7 +41,7 @@ int widget_intersect ( const Widget *widget, int x, int y);
|
|||
*
|
||||
* Moves the widget.
|
||||
*/
|
||||
void widget_move(Widget *widget, short x, short y);
|
||||
void widget_move ( Widget *widget, short x, short y );
|
||||
|
||||
/*@}*/
|
||||
#endif // ROFI_WIDGET_H
|
||||
|
|
|
@ -451,11 +451,11 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
|
|||
desktops = 1;
|
||||
}
|
||||
if ( pd->config_i3_mode ) {
|
||||
sprintf ( pattern, "%%-%ds %%s", MAX ( 5, classfield ) );
|
||||
snprintf ( pattern, 50, "%%-%ds %%s", MAX ( 5, classfield ) );
|
||||
}
|
||||
else{
|
||||
sprintf ( pattern, "%%-%ds %%-%ds %%s", desktops < 10 ? 1 : 2,
|
||||
MAX ( 5, classfield ) );
|
||||
snprintf ( pattern, 50, "%%-%ds %%-%ds %%s", desktops < 10 ? 1 : 2,
|
||||
MAX ( 5, classfield ) );
|
||||
}
|
||||
pd->cmd_list = g_malloc0_n ( ( pd->ids->len + 1 ), sizeof ( char* ) );
|
||||
|
||||
|
@ -469,7 +469,8 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
|
|||
unsigned long wmdesktop;
|
||||
char desktop[5];
|
||||
desktop[0] = 0;
|
||||
char *line = g_malloc ( strlen ( c->title ) + strlen ( c->class ) + classfield + 50 );
|
||||
size_t len = strlen ( c->title ) + strlen ( c->class ) + classfield + 50;
|
||||
char *line = g_malloc ( len );
|
||||
if ( !pd->config_i3_mode ) {
|
||||
// find client's desktop.
|
||||
if ( !window_get_cardinal_prop ( display, c->window, netatoms[_NET_WM_DESKTOP], &wmdesktop, 1 ) ) {
|
||||
|
@ -482,13 +483,13 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
|
|||
}
|
||||
|
||||
if ( wmdesktop < 0xFFFFFFFF ) {
|
||||
sprintf ( desktop, "%d", (int) wmdesktop );
|
||||
snprintf ( desktop, 5, "%d", (int) wmdesktop );
|
||||
}
|
||||
|
||||
sprintf ( line, pattern, desktop, c->class, c->title );
|
||||
snprintf ( line, len, pattern, desktop, c->class, c->title );
|
||||
}
|
||||
else{
|
||||
sprintf ( line, pattern, c->class, c->title );
|
||||
snprintf ( line, len, pattern, c->class, c->title );
|
||||
}
|
||||
|
||||
pd->cmd_list[pd->cmd_list_length++] = line;
|
||||
|
|
|
@ -742,13 +742,13 @@ static void menu_mouse_navigation ( MenuState *state, XButtonEvent *xbe )
|
|||
return;
|
||||
}
|
||||
else {
|
||||
if ( state->scrollbar && widget_intersect ( &(state->scrollbar->widget), xbe->x, xbe->y ) ) {
|
||||
if ( state->scrollbar && widget_intersect ( &( state->scrollbar->widget ), xbe->x, xbe->y ) ) {
|
||||
state->selected = scrollbar_clicked ( state->scrollbar, xbe->y );
|
||||
state->update = TRUE;
|
||||
return;
|
||||
}
|
||||
for ( unsigned int i = 0; config.sidebar_mode == TRUE && i < num_modi; i++ ) {
|
||||
if ( widget_intersect ( &(modi[i].tb->widget), xbe->x, xbe->y ) ) {
|
||||
if ( widget_intersect ( &( modi[i].tb->widget ), xbe->x, xbe->y ) ) {
|
||||
*( state->selected_line ) = 0;
|
||||
state->retv = MENU_QUICK_SWITCH | ( i & MENU_LOWER_MASK );
|
||||
state->quit = TRUE;
|
||||
|
@ -757,7 +757,7 @@ static void menu_mouse_navigation ( MenuState *state, XButtonEvent *xbe )
|
|||
}
|
||||
}
|
||||
for ( unsigned int i = 0; i < state->max_elements; i++ ) {
|
||||
if ( widget_intersect ( &(state->boxes[i]->widget), xbe->x, xbe->y ) ) {
|
||||
if ( widget_intersect ( &( state->boxes[i]->widget ), xbe->x, xbe->y ) ) {
|
||||
// Only allow items that are visible to be selected.
|
||||
if ( ( state->last_offset + i ) >= state->filtered_lines ) {
|
||||
break;
|
||||
|
@ -1128,7 +1128,7 @@ static void menu_paste ( MenuState *state, XSelectionEvent *xse )
|
|||
static void menu_resize ( MenuState *state )
|
||||
{
|
||||
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 ) {
|
||||
int width = ( state->w - ( 2 * ( state->border ) + ( num_modi - 1 ) * config.line_margin ) ) / num_modi;
|
||||
for ( unsigned int j = 0; j < num_modi; j++ ) {
|
||||
|
@ -1141,7 +1141,7 @@ static void menu_resize ( MenuState *state )
|
|||
int entrybox_width = state->w - ( 2 * ( state->border ) ) - textbox_get_width ( state->prompt_tb )
|
||||
- textbox_get_width ( state->case_indicator );
|
||||
textbox_moveresize ( state->text, state->text->widget.x, state->text->widget.y, entrybox_width, state->line_height );
|
||||
widget_move ( WIDGET(state->case_indicator), state->w - state->border - textbox_get_width ( state->case_indicator ), state->border );
|
||||
widget_move ( WIDGET ( state->case_indicator ), state->w - state->border - textbox_get_width ( state->case_indicator ), state->border );
|
||||
/**
|
||||
* Resize in Height
|
||||
*/
|
||||
|
@ -1334,7 +1334,7 @@ MenuReturn menu ( Mode *sw, char **input, char *prompt, unsigned int *selected_l
|
|||
state.top_offset = state.border * 1 + state.line_height + 2 + config.line_margin * 2;
|
||||
|
||||
// Move indicator to end.
|
||||
widget_move ( WIDGET(state.case_indicator), state.border + textbox_get_width ( state.prompt_tb ) + entrybox_width, state.border );
|
||||
widget_move ( WIDGET ( state.case_indicator ), state.border + textbox_get_width ( state.prompt_tb ) + entrybox_width, state.border );
|
||||
|
||||
textbox_text ( state.case_indicator, get_matching_state () );
|
||||
state.message_tb = NULL;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
#include <glib.h>
|
||||
#include "widget.h"
|
||||
|
||||
|
||||
int widget_intersect ( const Widget *widget, int x, int y)
|
||||
int widget_intersect ( const Widget *widget, int x, int y )
|
||||
{
|
||||
if(widget == NULL ){
|
||||
if ( widget == NULL ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -14,14 +13,12 @@ int widget_intersect ( const Widget *widget, int x, int y)
|
|||
}
|
||||
}
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
void widget_move(Widget *widget, short x, short y)
|
||||
void widget_move ( Widget *widget, short x, short y )
|
||||
{
|
||||
if ( widget != NULL ){
|
||||
if ( widget != NULL ) {
|
||||
widget->x = x;
|
||||
widget->y = y;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -170,7 +170,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
|
|||
textbox_font ( box, HIGHLIGHT );
|
||||
textbox_draw ( box, draw );
|
||||
|
||||
widget_move ( WIDGET(box), 12, 13 );
|
||||
widget_move ( WIDGET ( box ), 12, 13 );
|
||||
TASSERT ( box->widget.x == 12 );
|
||||
TASSERT ( box->widget.y == 13 );
|
||||
|
||||
|
|
Loading…
Reference in a new issue