1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Adjust new editor width

This commit is contained in:
QC 2015-09-19 12:57:48 +02:00
parent 442e235c24
commit b18d68eff2
24 changed files with 258 additions and 504 deletions

View file

@ -1,7 +1,9 @@
# #
# My favorite format # My favorite format
# #
code_width = 100 code_width = 140
nl_max = 2
ls_func_split_full = True
indent_with_tabs = 0 # 1=indent to level only, 2=indent with tabs indent_with_tabs = 0 # 1=indent to level only, 2=indent with tabs
input_tab_size = 8 # original tab size input_tab_size = 8 # original tab size
output_tab_size = 4 # new tab size output_tab_size = 4 # new tab size

View file

@ -1,7 +1,6 @@
#ifndef __DMENU_DIALOG_H__ #ifndef __DMENU_DIALOG_H__
#define __DMENU_DIALOG_H__ #define __DMENU_DIALOG_H__
/** /**
* dmenu dialog. * dmenu dialog.
* *

View file

@ -1,7 +1,6 @@
#ifndef __SCRIPT_DIALOG_H__ #ifndef __SCRIPT_DIALOG_H__
#define __SCRIPT_DIALOG_H__ #define __SCRIPT_DIALOG_H__
/** /**
* @param str The input string to parse * @param str The input string to parse
* *

View file

@ -71,7 +71,6 @@ int find_arg_uint ( const char * const key, unsigned int *val );
*/ */
int find_arg_int ( const char * const key, int *val ); int find_arg_int ( const char * const key, int *val );
/** /**
* @param key The key to search for * @param key The key to search for
* @param val Pointer to the string to set to the key value (if found) * @param val Pointer to the string to set to the key value (if found)

View file

@ -10,7 +10,6 @@
*/ */
void history_set ( const char *filename, const char *entry ) __attribute__( ( nonnull ) ); void history_set ( const char *filename, const char *entry ) __attribute__( ( nonnull ) );
/** /**
* @param filename The filename of the history cache. * @param filename The filename of the history cache.
* @param entry The entry to remove * @param entry The entry to remove
@ -19,7 +18,6 @@ void history_set ( const char *filename, const char *entry ) __attribute__( ( no
*/ */
void history_remove ( const char *filename, const char *entry ) __attribute__( ( nonnull ) ); void history_remove ( const char *filename, const char *entry ) __attribute__( ( nonnull ) );
/** /**
* @param filename The filename of the history cache. * @param filename The filename of the history cache.
* @param length The length of the returned list. * @param length The length of the returned list.

View file

@ -56,7 +56,6 @@ typedef enum _KeyBindingAction
NUM_ABE NUM_ABE
} KeyBindingAction; } KeyBindingAction;
/** /**
* Parse the keybindings. * Parse the keybindings.
* This should be called after the setting system is initialized. * This should be called after the setting system is initialized.

View file

@ -37,7 +37,6 @@ typedef enum
typedef SwitcherMode ( *switcher_callback )( char **input, void *data ); typedef SwitcherMode ( *switcher_callback )( char **input, void *data );
typedef void ( *switcher_free )( Switcher *data ); typedef void ( *switcher_free )( Switcher *data );
typedef const char * ( *get_display_value )( unsigned int selected_line, void *data, int *state ); typedef const char * ( *get_display_value )( unsigned int selected_line, void *data, int *state );
/** /**
* State returned by the rofi window. * State returned by the rofi window.
@ -64,7 +63,6 @@ typedef enum
MENU_LOWER_MASK = 0x0000FFFF MENU_LOWER_MASK = 0x0000FFFF
} MenuReturn; } MenuReturn;
/** /**
* @param tokens List of (input) tokens to match. * @param tokens List of (input) tokens to match.
* @param input The entry to match against. * @param input The entry to match against.
@ -76,8 +74,7 @@ typedef enum
* *
* @returns 1 when it matches, 0 if not. * @returns 1 when it matches, 0 if not.
*/ */
typedef int ( *menu_match_cb )( char **tokens, const char *input, int case_sensitive, typedef int ( *menu_match_cb )( char **tokens, const char *input, int case_sensitive, unsigned int index, Switcher *data );
unsigned int index, Switcher *data );
/** /**
* @param sw the Switcher to show. * @param sw the Switcher to show.
@ -95,10 +92,9 @@ typedef int ( *menu_match_cb )( char **tokens, const char *input, int case_sensi
* *
* @returns The command issued (see MenuReturn) * @returns The command issued (see MenuReturn)
*/ */
MenuReturn menu ( Switcher *sw, char **input, char *prompt, MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *selected_line, unsigned int *next_pos, const char *message )
unsigned int *selected_line, __attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );
unsigned int *next_pos,
const char *message ) __attribute__ ( ( nonnull ( 1, 2, 3, 4 ) ) );
/** /**
* @param sig The caught signal * @param sig The caught signal
* *
@ -268,7 +264,6 @@ struct _Switcher
KeySym keysym; KeySym keysym;
unsigned int modmask; unsigned int modmask;
/** /**
* A switcher normally consists of the following parts: * A switcher normally consists of the following parts:
*/ */
@ -313,7 +308,5 @@ struct _Switcher
#define color_magenta_bold "\033[1;35m" #define color_magenta_bold "\033[1;35m"
#define color_cyan_bold "\033[1;36m" #define color_cyan_bold "\033[1;36m"
int show_error_message ( const char *msg, int markup ); int show_error_message ( const char *msg, int markup );
#endif #endif

View file

@ -21,7 +21,6 @@ typedef struct
int changed; int changed;
} textbox; } textbox;
typedef enum typedef enum
{ {
TB_AUTOHEIGHT = 1 << 0, TB_AUTOHEIGHT = 1 << 0,
@ -33,7 +32,6 @@ typedef enum
TB_MARKUP = 1 << 20, TB_MARKUP = 1 << 20,
} TextboxFlags; } TextboxFlags;
typedef enum typedef enum
{ {
// Render font normally // Render font normally
@ -202,7 +200,6 @@ int textbox_get_font_width ( textbox *tb );
*/ */
double textbox_get_estimated_char_width ( void ); double textbox_get_estimated_char_width ( void );
/** /**
* @param tb Handle to the textbox * @param tb Handle to the textbox
* *
@ -243,6 +240,5 @@ void textbox_delete ( textbox *tb, int pos, int dlen );
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ); void textbox_moveresize ( textbox *tb, int x, int y, int w, int h );
int textbox_get_estimated_char_height ( void ); int textbox_get_estimated_char_height ( void );
void textbox_text_markup ( textbox *tb, const char *text ); void textbox_text_markup ( textbox *tb, const char *text );
#endif //ROFI_TEXTBOX_H #endif //ROFI_TEXTBOX_H

View file

@ -1,7 +1,6 @@
#ifndef X11_ROFI_HELPER_H #ifndef X11_ROFI_HELPER_H
#define X11_ROFI_HELPER_H #define X11_ROFI_HELPER_H
int window_get_prop ( Display *display, Window w, Atom prop, int window_get_prop ( Display *display, Window w, Atom prop,
Atom *type, int *items, Atom *type, int *items,
void *buffer, unsigned int bytes ) __attribute__ ( ( nonnull ( 4, 5 ) ) ); void *buffer, unsigned int bytes ) __attribute__ ( ( nonnull ( 4, 5 ) ) );
@ -23,7 +22,6 @@ void window_set_atom_prop ( Display *display, Window w, Atom prop, Atom *atoms,
int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list, int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list,
int count ); int count );
/** /**
* Window info. * Window info.
*/ */
@ -142,7 +140,6 @@ void x11_setup ( Display *display );
*/ */
void create_visual_and_colormap ( Display *display ); void create_visual_and_colormap ( Display *display );
/** /**
* @param display Connection to the X server. * @param display Connection to the X server.
* @param name String representing the color. * @param name String representing the color.

View file

@ -20,7 +20,6 @@ typedef enum
*/ */
void config_parse_xresource_options ( Display *display ); void config_parse_xresource_options ( Display *display );
/** /**
* Parse commandline options. * Parse commandline options.
*/ */

View file

@ -57,7 +57,6 @@ typedef struct _DmenuModePrivateData
unsigned int cmd_list_length; unsigned int cmd_list_length;
} DmenuModePrivateData; } DmenuModePrivateData;
static char **get_dmenu ( unsigned int *length ) static char **get_dmenu ( unsigned int *length )
{ {
char buffer[1024]; char buffer[1024];
@ -96,7 +95,6 @@ static char ** dmenu_mode_get_data ( unsigned int *length, Switcher *sw )
return rmpd->cmd_list; return rmpd->cmd_list;
} }
static void parse_pair ( char *input, struct range_pair *item ) static void parse_pair ( char *input, struct range_pair *item )
{ {
int index = 0; int index = 0;
@ -209,7 +207,6 @@ static void dmenu_mode_free ( Switcher *sw )
} }
DmenuModePrivateData *pd = (DmenuModePrivateData *) sw->private_data; DmenuModePrivateData *pd = (DmenuModePrivateData *) sw->private_data;
g_strfreev ( pd->cmd_list ); g_strfreev ( pd->cmd_list );
g_free ( pd->urgent_list ); g_free ( pd->urgent_list );
g_free ( pd->active_list ); g_free ( pd->active_list );
@ -295,7 +292,6 @@ int dmenu_switcher_dialog ( void )
unsigned int cmd_list_length = 0; unsigned int cmd_list_length = 0;
char **cmd_list = dmenu_mode.get_data ( &( cmd_list_length ), &dmenu_mode ); char **cmd_list = dmenu_mode.get_data ( &( cmd_list_length ), &dmenu_mode );
int only_selected = FALSE; int only_selected = FALSE;
if ( find_arg ( "-only-match" ) >= 0 || find_arg ( "-no-custom" ) >= 0 ) { if ( find_arg ( "-only-match" ) >= 0 || find_arg ( "-no-custom" ) >= 0 ) {
only_selected = TRUE; only_selected = TRUE;
@ -392,7 +388,6 @@ int dmenu_switcher_dialog ( void )
} }
} while ( restart ); } while ( restart );
g_free ( input ); g_free ( input );
dmenu_mode.destroy ( &dmenu_mode ); dmenu_mode.destroy ( &dmenu_mode );
return retv; return retv;

View file

@ -79,7 +79,6 @@ static void exec_cmd ( const char *cmd, int run_in_term )
return; return;
} }
execsh ( cmd, run_in_term ); execsh ( cmd, run_in_term );
/** /**
@ -155,7 +154,6 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i
retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) ); retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) );
retv[( *length )] = g_strdup ( buffer ); retv[( *length )] = g_strdup ( buffer );
( *length )++; ( *length )++;
} }
if ( fclose ( inp ) != 0 ) { if ( fclose ( inp ) != 0 ) {
@ -181,14 +179,12 @@ static char ** get_apps ( unsigned int *length )
return NULL; return NULL;
} }
path = g_strdup_printf ( "%s/%s", cache_dir, RUN_CACHE_FILE ); path = g_strdup_printf ( "%s/%s", cache_dir, RUN_CACHE_FILE );
retv = history_get_list ( path, length ); retv = history_get_list ( path, length );
g_free ( path ); g_free ( path );
// Keep track of how many where loaded as favorite. // Keep track of how many where loaded as favorite.
num_favorites = ( *length ); num_favorites = ( *length );
path = g_strdup ( getenv ( "PATH" ) ); path = g_strdup ( getenv ( "PATH" ) );
for ( const char *dirname = strtok ( path, ":" ); for ( const char *dirname = strtok ( path, ":" );
@ -259,7 +255,6 @@ static char ** get_apps ( unsigned int *length )
} }
} }
if ( ( *length ) > num_favorites ) { if ( ( *length ) > num_favorites ) {
g_qsort_with_data ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ), g_qsort_with_data ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ),
sort_func, sort_func,
@ -278,7 +273,6 @@ typedef struct _RunModePrivateData
unsigned int cmd_list_length; unsigned int cmd_list_length;
} RunModePrivateData; } RunModePrivateData;
static void run_mode_init ( Switcher *sw ) static void run_mode_init ( Switcher *sw )
{ {
if ( sw->private_data == NULL ) { if ( sw->private_data == NULL ) {
@ -333,7 +327,6 @@ static SwitcherMode run_mode_result ( int mretv, char **input, unsigned int sele
return retv; return retv;
} }
static void run_mode_destroy ( Switcher *sw ) static void run_mode_destroy ( Switcher *sw )
{ {
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data; RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;

View file

@ -25,7 +25,6 @@
* *
*/ */
#include <config.h> #include <config.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -39,10 +38,6 @@
#include "dialogs/script.h" #include "dialogs/script.h"
#include "helper.h" #include "helper.h"
static char **get_script_output ( const char *command, unsigned int *length ) static char **get_script_output ( const char *command, unsigned int *length )
{ {
char **retv = NULL; char **retv = NULL;
@ -102,7 +97,6 @@ typedef struct _ScriptModePrivateData
unsigned int cmd_list_length; unsigned int cmd_list_length;
} ScriptModePrivateData; } ScriptModePrivateData;
static void script_mode_init ( Switcher *sw ) static void script_mode_init ( Switcher *sw )
{ {
if ( sw->private_data == NULL ) { if ( sw->private_data == NULL ) {
@ -145,7 +139,6 @@ static SwitcherMode script_mode_result ( int mretv, char **input, unsigned int s
new_list = execute_executor ( sw, *input, &new_length ); new_list = execute_executor ( sw, *input, &new_length );
} }
// If a new list was generated, use that an loop around. // If a new list was generated, use that an loop around.
if ( new_list != NULL ) { if ( new_list != NULL ) {
g_strfreev ( rmpd->cmd_list ); g_strfreev ( rmpd->cmd_list );

View file

@ -44,7 +44,6 @@
#include "i3-support.h" #include "i3-support.h"
#include "dialogs/window.h" #include "dialogs/window.h"
#define WINLIST 32 #define WINLIST 32
#define CLIENTTITLE 100 #define CLIENTTITLE 100
@ -417,8 +416,6 @@ static char ** _window_mode_get_data ( unsigned int *length, Switcher *sw, unsig
// if we happen to have a window destroyed while we're working... // if we happen to have a window destroyed while we're working...
pd->ids = winlist_new (); pd->ids = winlist_new ();
// calc widths of fields // calc widths of fields
for ( i = nwins - 1; i > -1; i-- ) { for ( i = nwins - 1; i > -1; i-- ) {
client *c; client *c;
@ -549,7 +546,6 @@ static SwitcherMode window_mode_result ( int mretv, G_GNUC_UNUSED char **input,
return retv; return retv;
} }
static void window_mode_destroy ( Switcher *sw ) static void window_mode_destroy ( Switcher *sw )
{ {
SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data; SwitcherModePrivateData *rmpd = (SwitcherModePrivateData *) sw->private_data;

View file

@ -84,9 +84,7 @@ char* fgets_s ( char* s, int n, FILE *iop, char sep )
* *
* @returns TRUE to stop replacement, FALSE to continue * @returns TRUE to stop replacement, FALSE to continue
*/ */
static gboolean helper_eval_cb ( const GMatchInfo *info, static gboolean helper_eval_cb ( const GMatchInfo *info, GString *res, gpointer data )
GString *res,
gpointer data )
{ {
gchar *match; gchar *match;
// Get the match // Get the match
@ -131,10 +129,7 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... )
// Replace hits within {-\w+}. // Replace hits within {-\w+}.
GRegex *reg = g_regex_new ( "{[-\\w]+}", 0, 0, NULL ); GRegex *reg = g_regex_new ( "{[-\\w]+}", 0, 0, NULL );
char *res = g_regex_replace_eval ( reg, char *res = g_regex_replace_eval ( reg, string, -1, 0, 0, helper_eval_cb, h, NULL );
string, -1,
0, 0, helper_eval_cb, h,
NULL );
// Free regex. // Free regex.
g_regex_unref ( reg ); g_regex_unref ( reg );
// Destroy key-value storage. // Destroy key-value storage.
@ -147,8 +142,7 @@ int helper_parse_setup ( char * string, char ***output, int *length, ... )
g_free ( res ); g_free ( res );
// Throw error if shell parsing fails. // Throw error if shell parsing fails.
if ( error ) { if ( error ) {
char *msg = g_strdup_printf ( "Failed to parse: '%s'\nError: '%s'", string, char *msg = g_strdup_printf ( "Failed to parse: '%s'\nError: '%s'", string, error->message );
error->message );
error_dialog ( msg, FALSE ); error_dialog ( msg, FALSE );
g_free ( msg ); g_free ( msg );
// print error. // print error.
@ -190,9 +184,7 @@ char **tokenize ( const char *input, int case_sensitive )
// Iterate over tokens. // Iterate over tokens.
// strtok should still be valid for utf8. // strtok should still be valid for utf8.
for ( token = strtok_r ( str, " ", &saveptr ); for ( token = strtok_r ( str, " ", &saveptr ); token != NULL; token = strtok_r ( NULL, " ", &saveptr ) ) {
token != NULL;
token = strtok_r ( NULL, " ", &saveptr ) ) {
retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) ); retv = g_realloc ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
retv[num_tokens] = token_collate_key ( token, case_sensitive ); retv[num_tokens] = token_collate_key ( token, case_sensitive );
retv[num_tokens + 1] = NULL; retv[num_tokens + 1] = NULL;
@ -368,19 +360,10 @@ int execute_generator ( const char * cmd )
int fd = -1; int fd = -1;
GError *error = NULL; GError *error = NULL;
g_spawn_async_with_pipes ( NULL, g_spawn_async_with_pipes ( NULL, args, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, &fd, NULL, &error );
args,
NULL,
G_SPAWN_SEARCH_PATH,
NULL,
NULL,
NULL,
NULL, &fd, NULL,
&error );
if ( error != NULL ) { if ( error != NULL ) {
char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", cmd, error->message );
error->message );
error_dialog ( msg, FALSE ); error_dialog ( msg, FALSE );
g_free ( msg ); g_free ( msg );
// print error. // print error.
@ -391,7 +374,6 @@ int execute_generator ( const char * cmd )
return fd; return fd;
} }
int create_pid_file ( const char *pidfile ) int create_pid_file ( const char *pidfile )
{ {
if ( pidfile == NULL ) { if ( pidfile == NULL ) {
@ -452,39 +434,31 @@ void config_sanity_check ( )
GString *msg = g_string_new ( GString *msg = g_string_new (
"<big><b>The configuration failed to validate:</b></big>\n" ); "<big><b>The configuration failed to validate:</b></big>\n" );
if ( config.element_height < 1 ) { if ( config.element_height < 1 ) {
g_string_append_printf ( g_string_append_printf ( msg, "\t<b>config.element_height</b>=%d is invalid. An element needs to be atleast 1 line high.\n",
msg,
"\t<b>config.element_height</b>=%d is invalid. An element needs to be atleast 1 line high.\n",
config.element_height ); config.element_height );
config.element_height = 1; config.element_height = 1;
found_error = TRUE; found_error = TRUE;
} }
if ( config.menu_columns == 0 ) { if ( config.menu_columns == 0 ) {
g_string_append_printf ( g_string_append_printf ( msg, "\t<b>config.menu_columns</b>=%d is invalid. You need at least one visible column.\n",
msg,
"\t<b>config.menu_columns</b>=%d is invalid. You need at least one visible column.\n",
config.menu_columns ); config.menu_columns );
config.menu_columns = 1; config.menu_columns = 1;
found_error = TRUE; found_error = TRUE;
} }
if ( config.menu_width == 0 ) { if ( config.menu_width == 0 ) {
show_error_message ( show_error_message ( "<b>config.menu_width</b>=0 is invalid. You cannot have a window with no width.", TRUE );
"<b>config.menu_width</b>=0 is invalid. You cannot have a window with no width.", TRUE );
config.menu_columns = 50; config.menu_columns = 50;
found_error = TRUE; found_error = TRUE;
} }
if ( !( config.location >= WL_CENTER && config.location <= WL_WEST ) ) { if ( !( config.location >= WL_CENTER && config.location <= WL_WEST ) ) {
g_string_append_printf ( g_string_append_printf ( msg, "\t<b>config.location</b>=%d is invalid. Value should be between %d and %d.\n",
msg, "\t<b>config.location</b>=%d is invalid. Value should be between %d and %d.\n",
config.location, WL_CENTER, WL_WEST ); config.location, WL_CENTER, WL_WEST );
config.location = WL_CENTER; config.location = WL_CENTER;
found_error = 1; found_error = 1;
} }
if ( 0 ) { if ( 0 ) {
if ( !( config.line_margin <= 50 ) ) { if ( !( config.line_margin <= 50 ) ) {
g_string_append_printf ( g_string_append_printf ( msg, "\t<b>config.line_margin</b>=%d is invalid. Value should be between %d and %d.\n",
msg,
"\t<b>config.line_margin</b>=%d is invalid. Value should be between %d and %d.\n",
config.line_margin, 0, 50 ); config.line_margin, 0, 50 );
config.line_margin = 2; config.line_margin = 2;
found_error = 1; found_error = 1;

View file

@ -109,7 +109,6 @@ static _element ** __history_get_element_list ( FILE *fd, unsigned int *length )
return retv; return retv;
} }
void history_set ( const char *filename, const char *entry ) void history_set ( const char *filename, const char *entry )
{ {
if ( config.disable_history ) { if ( config.disable_history ) {

View file

@ -76,7 +76,6 @@ void i3_support_focus_window ( Window id )
return; return;
} }
// Formulate command // Formulate command
snprintf ( command, upm, "[id=\"%lu\"] focus", id ); snprintf ( command, upm, "[id=\"%lu\"] focus", id );
// Prepare header. // Prepare header.
@ -141,7 +140,6 @@ void i3_support_free_internals ( void )
#else #else
void i3_support_focus_window ( Window id ) void i3_support_focus_window ( Window id )
{ {
fprintf ( stderr, "Trying to control i3, when i3 support is not enabled.\n" ); fprintf ( stderr, "Trying to control i3, when i3 support is not enabled.\n" );

View file

@ -34,63 +34,36 @@ extern unsigned int NumlockMask;
*/ */
DefaultBinding bindings[NUM_ABE] = DefaultBinding bindings[NUM_ABE] =
{ {
{ .id = PASTE_PRIMARY, .name = "kb-primary-paste", { .id = PASTE_PRIMARY, .name = "kb-primary-paste", .keybinding = "Control+Shift+v,Shift+Insert", },
.keybinding = { .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding = "Control+v,Insert", },
"Control+Shift+v,Shift+Insert", }, { .id = CLEAR_LINE, .name = "kb-clear-line", .keybinding = "Control+u", },
{ .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding = { .id = MOVE_FRONT, .name = "kb-move-front", .keybinding = "Control+a", },
"Control+v,Insert", }, { .id = MOVE_END, .name = "kb-move-end", .keybinding = "Control+e", },
{ .id = CLEAR_LINE, .name = "kb-clear-line", .keybinding =
"Control+u", },
{ .id = MOVE_FRONT, .name = "kb-move-front", .keybinding =
"Control+a", },
{ .id = MOVE_END, .name = "kb-move-end", .keybinding =
"Control+e", },
{ .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .keybinding = "Alt+b", }, { .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .keybinding = "Alt+b", },
{ .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .keybinding = "Alt+f", }, { .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .keybinding = "Alt+f", },
{ .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding = { .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding = "Left,Control+b" },
"Left,Control+b" }, { .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding = "Right,Control+f" },
{ .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding = { .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding = "Control+Alt+h", },
"Right,Control+f" }, { .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding = "Control+Alt+d", },
{ .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding = { .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = "Delete,Control+d", },
"Control+Alt+h", }, { .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = "BackSpace,Control+h", },
{ .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding = { .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = "Control+j,Control+m,Return,KP_Enter", },
"Control+Alt+d", }, { .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = "Control+Return", },
{ .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = { .id = ACCEPT_ENTRY_CONTINUE, .name = "kb-accept-entry-continue", .keybinding = "Shift+Return", },
"Delete,Control+d", }, { .id = MODE_NEXT, .name = "kb-mode-next", .keybinding = "Shift+Right,Control+Tab" },
{ .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = { .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding = "Shift+Left,Control+Shift+Tab" },
"BackSpace,Control+h", }, { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .keybinding = "grave,dead_grave" },
{ .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = { .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding = "Shift+Delete" },
"Control+j,Control+m,Return,KP_Enter", }, { .id = ROW_LEFT, .name = "kb-row-left", .keybinding = "Control+Page_Up" },
{ .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = { .id = ROW_RIGHT, .name = "kb-row-right", .keybinding = "Control+Page_Down" },
"Control+Return", }, { .id = ROW_UP, .name = "kb-row-up", .keybinding = "Up,Control+p,Shift+Tab" },
{ .id = ACCEPT_ENTRY_CONTINUE, .name = "kb-accept-entry-continue", .keybinding = { .id = ROW_DOWN, .name = "kb-row-down", .keybinding = "Down,Control+n" },
"Shift+Return", },
{ .id = MODE_NEXT, .name = "kb-mode-next", .keybinding =
"Shift+Right,Control+Tab" },
{ .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding =
"Shift+Left,Control+Shift+Tab" },
{ .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .keybinding =
"grave,dead_grave" },
{ .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding =
"Shift+Delete" },
{ .id = ROW_LEFT, .name = "kb-row-left", .keybinding =
"Control+Page_Up" },
{ .id = ROW_RIGHT, .name = "kb-row-right", .keybinding =
"Control+Page_Down" },
{ .id = ROW_UP, .name = "kb-row-up", .keybinding =
"Up,Control+p,Shift+Tab" },
{ .id = ROW_DOWN, .name = "kb-row-down", .keybinding =
"Down,Control+n" },
{ .id = ROW_TAB, .name = "kb-row-tab", .keybinding = "Tab" }, { .id = ROW_TAB, .name = "kb-row-tab", .keybinding = "Tab" },
{ .id = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up" }, { .id = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up" },
{ .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = { .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = "Page_Down" },
"Page_Down" }, { .id = ROW_FIRST, .name = "kb-row-first", .keybinding = "Home,KP_Home" },
{ .id = ROW_FIRST, .name = "kb-row-first", .keybinding = { .id = ROW_LAST, .name = "kb-row-last", .keybinding = "End,KP_End" },
"Home,KP_Home" }, { .id = ROW_SELECT, .name = "kb-row-select", .keybinding = "Control+space" },
{ .id = ROW_LAST, .name = "kb-row-last", .keybinding =
"End,KP_End" },
{ .id = ROW_SELECT, .name = "kb-row-select", .keybinding =
"Control+space" },
{ .id = CANCEL, .name = "kb-cancel", .keybinding = "Escape" }, { .id = CANCEL, .name = "kb-cancel", .keybinding = "Escape" },
{ .id = CUSTOM_1, .name = "kb-custom-1", .keybinding = "Alt+1" }, { .id = CUSTOM_1, .name = "kb-custom-1", .keybinding = "Alt+1" },
{ .id = CUSTOM_2, .name = "kb-custom-2", .keybinding = "Alt+2" }, { .id = CUSTOM_2, .name = "kb-custom-2", .keybinding = "Alt+2" },
@ -102,27 +75,17 @@ DefaultBinding bindings[NUM_ABE] =
{ .id = CUSTOM_8, .name = "kb-custom-8", .keybinding = "Alt+8" }, { .id = CUSTOM_8, .name = "kb-custom-8", .keybinding = "Alt+8" },
{ .id = CUSTOM_9, .name = "kb-custom-9", .keybinding = "Alt+9" }, { .id = CUSTOM_9, .name = "kb-custom-9", .keybinding = "Alt+9" },
{ .id = CUSTOM_10, .name = "kb-custom-10", .keybinding = "Alt+0" }, { .id = CUSTOM_10, .name = "kb-custom-10", .keybinding = "Alt+0" },
{ .id = CUSTOM_11, .name = "kb-custom-11", .keybinding = { .id = CUSTOM_11, .name = "kb-custom-11", .keybinding = "Alt+Shift+1" },
"Alt+Shift+1" }, { .id = CUSTOM_12, .name = "kb-custom-12", .keybinding = "Alt+Shift+2" },
{ .id = CUSTOM_12, .name = "kb-custom-12", .keybinding = { .id = CUSTOM_13, .name = "kb-custom-13", .keybinding = "Alt+Shift+3" },
"Alt+Shift+2" }, { .id = CUSTOM_14, .name = "kb-custom-14", .keybinding = "Alt+Shift+4" },
{ .id = CUSTOM_13, .name = "kb-custom-13", .keybinding = { .id = CUSTOM_15, .name = "kb-custom-15", .keybinding = "Alt+Shift+5" },
"Alt+Shift+3" }, { .id = CUSTOM_16, .name = "kb-custom-16", .keybinding = "Alt+Shift+6" },
{ .id = CUSTOM_14, .name = "kb-custom-14", .keybinding = { .id = CUSTOM_17, .name = "kb-custom-17", .keybinding = "Alt+Shift+7" },
"Alt+Shift+4" }, { .id = CUSTOM_18, .name = "kb-custom-18", .keybinding = "Alt+Shift+8" },
{ .id = CUSTOM_15, .name = "kb-custom-15", .keybinding = { .id = CUSTOM_19, .name = "kb-custom-19", .keybinding = "Alt+Shift+9" },
"Alt+Shift+5" },
{ .id = CUSTOM_16, .name = "kb-custom-16", .keybinding =
"Alt+Shift+6" },
{ .id = CUSTOM_17, .name = "kb-custom-17", .keybinding =
"Alt+Shift+7" },
{ .id = CUSTOM_18, .name = "kb-custom-18", .keybinding =
"Alt+Shift+8" },
{ .id = CUSTOM_19, .name = "kb-custom-19", .keybinding =
"Alt+Shift+9" },
}; };
void setup_abe ( void ) void setup_abe ( void )
{ {
for ( int iter = 0; iter < NUM_ABE; iter++ ) { for ( int iter = 0; iter < NUM_ABE; iter++ ) {
@ -133,8 +96,7 @@ void setup_abe ( void )
abe[id].num_bindings = 0; abe[id].num_bindings = 0;
abe[id].kb = NULL; abe[id].kb = NULL;
config_parser_add_option ( xrm_String, config_parser_add_option ( xrm_String, abe[id].name, (void * *) &( abe[id].keystr ) );
abe[id].name, (void * *) &( abe[id].keystr ) );
} }
} }

View file

@ -130,7 +130,6 @@ static inline MainLoopEvent wait_for_xevent_or_timeout ( Display *display, int x
return ML_XEVENT; return ML_XEVENT;
} }
/** /**
* Levenshtein Sorting. * Levenshtein Sorting.
*/ */
@ -199,9 +198,7 @@ static Window create_window ( Display *display )
Window box = XCreateWindow ( display, DefaultRootWindow ( display ), Window box = XCreateWindow ( display, DefaultRootWindow ( display ),
0, 0, 200, 100, config.menu_bw, vinfo.depth, InputOutput, 0, 0, 200, 100, config.menu_bw, vinfo.depth, InputOutput,
vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr ); vinfo.visual, CWColormap | CWBorderPixel | CWBackPixel, &attr );
XSelectInput ( display, box, XSelectInput ( display, box, KeyReleaseMask | KeyPressMask | ExposureMask | ButtonPressMask | StructureNotifyMask | FocusChangeMask );
KeyReleaseMask | KeyPressMask | ExposureMask |
ButtonPressMask | StructureNotifyMask | FocusChangeMask );
gc = XCreateGC ( display, box, 0, 0 ); gc = XCreateGC ( display, box, 0, 0 );
int line_style = LineOnOffDash; int line_style = LineOnOffDash;
@ -215,15 +212,12 @@ static Window create_window ( Display *display )
XSetForeground ( display, gc, color_separator ( display ) ); XSetForeground ( display, gc, color_separator ( display ) );
// make it an unmanaged window // make it an unmanaged window
if ( !normal_window_mode ) { if ( !normal_window_mode ) {
window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE], window_set_atom_prop ( display, box, netatoms[_NET_WM_STATE], &netatoms[_NET_WM_STATE_ABOVE], 1 );
&netatoms[_NET_WM_STATE_ABOVE],
1 );
XSetWindowAttributes sattr = { .override_redirect = True }; XSetWindowAttributes sattr = { .override_redirect = True };
XChangeWindowAttributes ( display, box, CWOverrideRedirect, &sattr ); XChangeWindowAttributes ( display, box, CWOverrideRedirect, &sattr );
} }
else{ else{
window_set_atom_prop ( display, box, netatoms[_NET_WM_WINDOW_TYPE], window_set_atom_prop ( display, box, netatoms[_NET_WM_WINDOW_TYPE], &netatoms[_NET_WM_WINDOW_TYPE_NORMAL], 1 );
&netatoms[_NET_WM_WINDOW_TYPE_NORMAL], 1 );
} }
// Set the WM_NAME // Set the WM_NAME
@ -353,7 +347,6 @@ static void calculate_window_position ( MenuState *state, const workarea *mon )
state->y += config.y_offset; state->y += config.y_offset;
} }
/** /**
* @param state Internal state of the menu. * @param state Internal state of the menu.
* *
@ -367,12 +360,10 @@ static void menu_calculate_rows_columns ( MenuState *state )
// Calculate the number or rows. We do this by getting the num_lines rounded up to X columns // Calculate the number or rows. We do this by getting the num_lines rounded up to X columns
// (num elements is better name) then dividing by columns. // (num elements is better name) then dividing by columns.
state->max_rows = MIN ( state->menu_lines, state->max_rows = MIN ( state->menu_lines, (unsigned int) ( ( state->num_lines +
(unsigned int) ( ( state->columns - state->num_lines %
( state->num_lines + state->columns ) % state->columns ) /
( state->columns - state->num_lines % state->columns ) % ( state->columns ) ) );
state->columns ) / ( state->columns )
) );
// Always have at least one row. // Always have at least one row.
state->max_rows = MAX ( 1, state->max_rows ); state->max_rows = MAX ( 1, state->max_rows );
@ -382,8 +373,7 @@ static void menu_calculate_rows_columns ( MenuState *state )
// If it would fit in one column, only use one column. // If it would fit in one column, only use one column.
if ( state->num_lines < state->max_elements ) { if ( state->num_lines < state->max_elements ) {
state->columns = state->columns =
( state->num_lines + ( state->max_rows - state->num_lines % state->max_rows ) % ( state->num_lines + ( state->max_rows - state->num_lines % state->max_rows ) % state->max_rows ) / state->max_rows;
state->max_rows ) / state->max_rows;
state->max_elements = state->menu_lines * state->columns; state->max_elements = state->menu_lines * state->columns;
} }
// Sanitize. // Sanitize.
@ -410,8 +400,7 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea
} }
else{ else{
// Calculate as float to stop silly, big rounding down errors. // Calculate as float to stop silly, big rounding down errors.
state->w = config.menu_width < state->w = config.menu_width < 101 ? ( mon->w / 100.0f ) * ( float ) config.menu_width : config.menu_width;
101 ? ( mon->w / 100.0f ) * ( float ) config.menu_width : config.menu_width;
// Compensate for border width. // Compensate for border width.
state->w -= config.menu_bw * 2; state->w -= config.menu_bw * 2;
} }
@ -419,8 +408,7 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea
if ( state->columns > 0 ) { if ( state->columns > 0 ) {
state->element_width = state->w - ( 2 * ( config.padding ) ); state->element_width = state->w - ( 2 * ( config.padding ) );
// Divide by the # columns // Divide by the # columns
state->element_width = state->element_width = ( state->element_width - ( state->columns - 1 ) * config.line_margin ) / state->columns;
( state->element_width - ( state->columns - 1 ) * config.line_margin ) / state->columns;
} }
} }
@ -525,8 +513,7 @@ inline static void menu_nav_up ( MenuState *state )
*/ */
inline static void menu_nav_down ( MenuState *state ) inline static void menu_nav_down ( MenuState *state )
{ {
state->selected = state->selected < state->filtered_lines - 1 ? MIN ( state->selected = state->selected < state->filtered_lines - 1 ? MIN ( state->filtered_lines - 1, state->selected + 1 ) : 0;
state->filtered_lines - 1, state->selected + 1 ) : 0;
state->update = TRUE; state->update = TRUE;
} }
/** /**
@ -715,8 +702,7 @@ static void menu_refilter ( MenuState *state )
// input changed // input changed
for ( unsigned int i = 0; i < state->num_lines; i++ ) { for ( unsigned int i = 0; i < state->num_lines; i++ ) {
int match = state->sw->token_match ( tokens, state->lines[i], config.case_sensitive, i, int match = state->sw->token_match ( tokens, state->lines[i], config.case_sensitive, i, state->sw );
state->sw );
// If each token was matched, add it to list. // If each token was matched, add it to list.
if ( match ) { if ( match ) {
@ -754,15 +740,13 @@ static void menu_refilter ( MenuState *state )
state->rchanged = TRUE; state->rchanged = TRUE;
} }
static void menu_draw ( MenuState *state ) static void menu_draw ( MenuState *state )
{ {
unsigned int i, offset = 0; unsigned int i, offset = 0;
// selected row is always visible. // selected row is always visible.
// If selected is visible do not scroll. // If selected is visible do not scroll.
if ( ( ( state->selected - ( state->last_offset ) ) < ( state->max_elements ) ) if ( ( ( state->selected - ( state->last_offset ) ) < ( state->max_elements ) ) && ( state->selected >= ( state->last_offset ) ) ) {
&& ( state->selected >= ( state->last_offset ) ) ) {
offset = state->last_offset; offset = state->last_offset;
} }
else{ else{
@ -782,8 +766,7 @@ static void menu_draw ( MenuState *state )
unsigned int a_lines = MIN ( ( state->filtered_lines - offset ), state->max_elements ); unsigned int a_lines = MIN ( ( state->filtered_lines - offset ), state->max_elements );
// Calculate number of columns // Calculate number of columns
unsigned int columns = ( a_lines + ( state->max_rows - a_lines % state->max_rows ) % unsigned int columns = ( a_lines + ( state->max_rows - a_lines % state->max_rows ) % state->max_rows ) / state->max_rows;
state->max_rows ) / state->max_rows;
columns = MIN ( columns, state->columns ); columns = MIN ( columns, state->columns );
// Update the handle length. // Update the handle length.
@ -814,16 +797,12 @@ static void menu_draw ( MenuState *state )
unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + config.line_margin ); unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + config.line_margin );
unsigned int ey = ( ( i ) % state->max_rows ) * ( element_height + config.line_margin ); unsigned int ey = ( ( i ) % state->max_rows ) * ( element_height + config.line_margin );
// Move it around. // Move it around.
textbox_moveresize ( state->boxes[i], textbox_moveresize ( state->boxes[i], ex + x_offset, ey + y_offset, element_width, element_height );
ex + x_offset, ey + y_offset,
element_width, element_height );
{ {
TextBoxFontType type = ( ( ( i % state->max_rows ) & 1 ) == 0 ) ? NORMAL : ALT; TextBoxFontType type = ( ( ( i % state->max_rows ) & 1 ) == 0 ) ? NORMAL : ALT;
int fstate = 0; int fstate = 0;
const char *text = state->sw->mgrv ( state->line_map[i + offset], state->sw, const char *text = state->sw->mgrv ( state->line_map[i + offset], state->sw, &fstate );
&fstate ); TextBoxFontType tbft = fstate | ( ( i + offset ) == state->selected ? HIGHLIGHT : type );
TextBoxFontType tbft = fstate |
( ( i + offset ) == state->selected ? HIGHLIGHT : type );
textbox_font ( state->boxes[i], tbft ); textbox_font ( state->boxes[i], tbft );
textbox_text ( state->boxes[i], text ); textbox_text ( state->boxes[i], text );
} }
@ -856,8 +835,7 @@ static void menu_update ( MenuState *state )
menu_draw ( state ); menu_draw ( state );
// Why do we need the special -1? // Why do we need the special -1?
XDrawLine ( display, main_window, gc, 0, XDrawLine ( display, main_window, gc, 0,
state->line_height + ( config.padding ) * 1 + config.line_margin + 1, state->line_height + ( config.padding ) * 1 + config.line_margin + 1, state->w,
state->w,
state->line_height + ( config.padding ) * 1 + config.line_margin + 1 ); state->line_height + ( config.padding ) * 1 + config.line_margin + 1 );
if ( state->message_tb ) { if ( state->message_tb ) {
XDrawLine ( display, main_window, gc, XDrawLine ( display, main_window, gc,
@ -867,10 +845,8 @@ static void menu_update ( MenuState *state )
if ( config.sidebar_mode == TRUE ) { if ( config.sidebar_mode == TRUE ) {
XDrawLine ( display, main_window, gc, XDrawLine ( display, main_window, gc,
0, 0, state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin,
state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin, state->w, state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin );
state->w,
state->h - state->line_height - ( config.padding ) * 1 - 1 - config.line_margin );
for ( unsigned int j = 0; j < num_switchers; j++ ) { for ( unsigned int j = 0; j < num_switchers; j++ ) {
textbox_draw ( switchers[j].tb ); textbox_draw ( switchers[j].tb );
} }
@ -912,13 +888,11 @@ static void menu_resize ( MenuState *state )
unsigned int sbw = config.line_margin + 8; unsigned int sbw = config.line_margin + 8;
scrollbar_move ( state->scrollbar, state->w - config.padding - sbw, state->top_offset ); scrollbar_move ( state->scrollbar, state->w - config.padding - sbw, state->top_offset );
if ( config.sidebar_mode == TRUE ) { if ( config.sidebar_mode == TRUE ) {
int width = ( state->w - ( 2 * ( config.padding ) + int width = ( state->w - ( 2 * ( config.padding ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
for ( unsigned int j = 0; j < num_switchers; j++ ) { for ( unsigned int j = 0; j < num_switchers; j++ ) {
textbox_moveresize ( switchers[j].tb, textbox_moveresize ( switchers[j].tb,
config.padding + j * ( width + config.line_margin ), config.padding + j * ( width + config.line_margin ),
state->h - state->line_height - config.padding, state->h - state->line_height - config.padding, width, state->line_height );
width, state->line_height );
textbox_show ( switchers[j].tb ); textbox_show ( switchers[j].tb );
textbox_draw ( switchers[j].tb ); textbox_draw ( switchers[j].tb );
} }
@ -928,8 +902,7 @@ static void menu_resize ( MenuState *state )
*/ */
{ {
unsigned int last_length = state->max_elements; unsigned int last_length = state->max_elements;
int element_height = state->line_height * config.element_height + int element_height = state->line_height * config.element_height + config.line_margin;
config.line_margin;
// Calculated new number of boxes. // Calculated new number of boxes.
unsigned int h = ( state->h - state->top_offset ); unsigned int h = ( state->h - state->top_offset );
if ( config.sidebar_mode == TRUE ) { if ( config.sidebar_mode == TRUE ) {
@ -948,21 +921,17 @@ static void menu_resize ( MenuState *state )
int x_offset = config.padding; int x_offset = config.padding;
// Add newly added boxes. // Add newly added boxes.
for ( unsigned int i = last_length; i < state->max_elements; i++ ) { for ( unsigned int i = last_length; i < state->max_elements; i++ ) {
state->boxes[i] = textbox_create ( main_window, &vinfo, map, 0, state->boxes[i] = textbox_create ( main_window, &vinfo, map, 0, x_offset, y_offset,
x_offset, y_offset,
state->element_width, element_height, NORMAL, "" ); state->element_width, element_height, NORMAL, "" );
} }
scrollbar_resize ( state->scrollbar, -1, scrollbar_resize ( state->scrollbar, -1, ( state->max_rows ) * ( element_height ) - config.line_margin );
( state->max_rows ) * ( element_height ) - config.line_margin );
} }
state->rchanged = TRUE; state->rchanged = TRUE;
state->update = TRUE; state->update = TRUE;
} }
MenuReturn menu ( Switcher *sw, char **input, char *prompt, MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *selected_line, unsigned int *next_pos, const char *message )
unsigned int *selected_line,
unsigned int *next_pos, const char *message )
{ {
int shift = FALSE; int shift = FALSE;
MenuState state = { MenuState state = {
@ -1016,8 +985,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
state.line_height = textbox_get_estimated_char_height (); state.line_height = textbox_get_estimated_char_height ();
state.case_indicator = textbox_create ( main_window, &vinfo, map, TB_AUTOWIDTH, state.case_indicator = textbox_create ( main_window, &vinfo, map, TB_AUTOWIDTH,
( config.padding ), ( config.padding ), ( config.padding ), ( config.padding ),
0, state.line_height, 0, state.line_height, NORMAL, "*" );
NORMAL, "*" );
// Height of a row. // Height of a row.
if ( config.menu_lines == 0 ) { if ( config.menu_lines == 0 ) {
// Autosize it. // Autosize it.
@ -1032,29 +1000,21 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
menu_calculate_window_and_element_width ( &state, &mon ); menu_calculate_window_and_element_width ( &state, &mon );
// Prompt box. // Prompt box.
state.prompt_tb = textbox_create ( main_window, &vinfo, map, TB_AUTOWIDTH, state.prompt_tb = textbox_create ( main_window, &vinfo, map, TB_AUTOWIDTH, ( config.padding ), ( config.padding ),
( config.padding ),
( config.padding ),
0, state.line_height, NORMAL, prompt ); 0, state.line_height, NORMAL, prompt );
// Entry box // Entry box
int entrybox_width = state.w int entrybox_width = state.w - ( 2 * ( config.padding ) )
- ( 2 * ( config.padding ) )
- textbox_get_width ( state.prompt_tb ) - textbox_get_width ( state.prompt_tb )
- textbox_get_width ( state.case_indicator ); - textbox_get_width ( state.case_indicator );
state.text = textbox_create ( main_window, &vinfo, map, TB_EDITABLE, state.text = textbox_create ( main_window, &vinfo, map, TB_EDITABLE,
( config.padding ) + textbox_get_width ( state.prompt_tb ), ( config.padding ) + textbox_get_width ( state.prompt_tb ), ( config.padding ),
( config.padding ), entrybox_width, state.line_height, NORMAL, *input );
entrybox_width, state.line_height,
NORMAL,
*input );
state.top_offset = config.padding * 1 + state.line_height + 2 + config.line_margin * 2; state.top_offset = config.padding * 1 + state.line_height + 2 + config.line_margin * 2;
// Move indicator to end. // Move indicator to end.
textbox_move ( state.case_indicator, textbox_move ( state.case_indicator, config.padding + textbox_get_width ( state.prompt_tb ) + entrybox_width, config.padding );
config.padding + textbox_get_width ( state.prompt_tb ) + entrybox_width,
config.padding );
textbox_show ( state.text ); textbox_show ( state.text );
textbox_show ( state.prompt_tb ); textbox_show ( state.prompt_tb );
@ -1065,14 +1025,9 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
state.message_tb = NULL; state.message_tb = NULL;
if ( message ) { if ( message ) {
// state.top_offset += config.line_margin;
state.message_tb = textbox_create ( main_window, &vinfo, map, TB_AUTOHEIGHT | TB_MARKUP, state.message_tb = textbox_create ( main_window, &vinfo, map, TB_AUTOHEIGHT | TB_MARKUP,
( config.padding ), ( config.padding ), state.top_offset, state.w - ( 2 * ( config.padding ) ),
state.top_offset, -1, NORMAL, message );
state.w - ( 2 * ( config.padding ) ),
-1,
NORMAL,
message );
textbox_show ( state.message_tb ); textbox_show ( state.message_tb );
state.top_offset += textbox_get_height ( state.message_tb ); state.top_offset += textbox_get_height ( state.message_tb );
state.top_offset += config.line_margin * 2 + 2; state.top_offset += config.line_margin * 2 + 2;
@ -1086,23 +1041,15 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
int x_offset = config.padding; int x_offset = config.padding;
for ( unsigned int i = 0; i < state.max_elements; i++ ) { for ( unsigned int i = 0; i < state.max_elements; i++ ) {
state.boxes[i] = textbox_create ( main_window, &vinfo, map, 0, state.boxes[i] = textbox_create ( main_window, &vinfo, map, 0, x_offset, y_offset,
x_offset, y_offset,
state.element_width, element_height, NORMAL, "" ); state.element_width, element_height, NORMAL, "" );
} }
if ( !config.hide_scrollbar ) { if ( !config.hide_scrollbar ) {
unsigned int sbw = config.line_margin + 8; unsigned int sbw = config.line_margin + 8;
state.scrollbar = scrollbar_create ( state.scrollbar = scrollbar_create ( main_window, &vinfo, map, state.w - config.padding - sbw, state.top_offset,
main_window, &vinfo, map, sbw, ( state.max_rows - 1 ) * ( element_height + config.line_margin ) + element_height );
state.w - config.padding - sbw,
state.top_offset,
sbw,
( state.max_rows -
1 ) *
( element_height + config.line_margin ) + element_height );
} }
scrollbar_set_max_value ( state.scrollbar, state.num_lines ); scrollbar_set_max_value ( state.scrollbar, state.num_lines );
// filtered list // filtered list
state.line_map = g_malloc0_n ( state.num_lines, sizeof ( unsigned int ) ); state.line_map = g_malloc0_n ( state.num_lines, sizeof ( unsigned int ) );
@ -1112,8 +1059,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
// resize window vertically to suit // resize window vertically to suit
// Subtract the margin of the last row. // Subtract the margin of the last row.
state.h = state.top_offset + state.h = state.top_offset + ( element_height + config.line_margin ) * ( state.max_rows ) - config.line_margin;
( element_height + config.line_margin ) * ( state.max_rows ) - config.line_margin;
state.h += config.padding; state.h += config.padding;
state.h += 0; state.h += 0;
// Add entry // Add entry
@ -1130,17 +1076,11 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
calculate_window_position ( &state, &mon ); calculate_window_position ( &state, &mon );
if ( config.sidebar_mode == TRUE ) { if ( config.sidebar_mode == TRUE ) {
int width = int width = ( state.w - ( 2 * ( config.padding ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
( state.w -
( 2 * ( config.padding ) +
( num_switchers - 1 ) * config.line_margin ) ) / num_switchers;
for ( unsigned int j = 0; j < num_switchers; j++ ) { for ( unsigned int j = 0; j < num_switchers; j++ ) {
switchers[j].tb = textbox_create ( main_window, &vinfo, map, TB_CENTER, switchers[j].tb = textbox_create ( main_window, &vinfo, map, TB_CENTER, config.padding + j * ( width + config.line_margin ),
config.padding + j * ( width + config.line_margin ), state.h - state.line_height - config.padding, width, state.line_height,
state.h - state.line_height - config.padding, ( j == curr_switcher ) ? HIGHLIGHT : NORMAL, switchers[j].sw->name );
width, state.line_height,
( j == curr_switcher ) ? HIGHLIGHT : NORMAL,
switchers[j].sw->name );
textbox_show ( switchers[j].tb ); textbox_show ( switchers[j].tb );
} }
} }
@ -1156,9 +1096,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
state.quit = FALSE; state.quit = FALSE;
menu_refilter ( &state ); menu_refilter ( &state );
for ( unsigned int i = 0; for ( unsigned int i = 0; ( *( state.selected_line ) ) < UINT32_MAX && !state.selected && i < state.filtered_lines; i++ ) {
( *( state.selected_line ) ) < UINT32_MAX && !state.selected && i < state.filtered_lines;
i++ ) {
if ( state.line_map[i] == *( state.selected_line ) ) { if ( state.line_map[i] == *( state.selected_line ) ) {
state.selected = i; state.selected = i;
break; break;
@ -1214,8 +1152,7 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
else if ( ev.type == ConfigureNotify ) { else if ( ev.type == ConfigureNotify ) {
XConfigureEvent xce = ev.xconfigure; XConfigureEvent xce = ev.xconfigure;
if ( xce.window == main_window ) { if ( xce.window == main_window ) {
if ( state.w != (unsigned int) xce.width || if ( state.w != (unsigned int) xce.width || state.h != (unsigned int ) xce.height ) {
state.h != (unsigned int ) xce.height ) {
state.w = xce.width; state.w = xce.width;
state.h = xce.height; state.h = xce.height;
menu_resize ( &state ); menu_resize ( &state );
@ -1263,13 +1200,10 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
// Handling of paste // Handling of paste
if ( abe_test_action ( PASTE_PRIMARY, ev.xkey.state, key ) ) { if ( abe_test_action ( PASTE_PRIMARY, ev.xkey.state, key ) ) {
XConvertSelection ( display, XA_PRIMARY, XConvertSelection ( display, XA_PRIMARY, netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window, CurrentTime );
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window,
CurrentTime );
} }
else if ( abe_test_action ( PASTE_SECONDARY, ev.xkey.state, key ) ) { else if ( abe_test_action ( PASTE_SECONDARY, ev.xkey.state, key ) ) {
XConvertSelection ( display, netatoms[CLIPBOARD], XConvertSelection ( display, netatoms[CLIPBOARD], netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window,
netatoms[UTF8_STRING], netatoms[UTF8_STRING], main_window,
CurrentTime ); CurrentTime );
} }
else if ( abe_test_action ( MODE_PREVIOUS, ev.xkey.state, key ) ) { else if ( abe_test_action ( MODE_PREVIOUS, ev.xkey.state, key ) ) {
@ -1374,7 +1308,6 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt,
} while ( ev.type != KeyRelease ); } while ( ev.type != KeyRelease );
} }
// Update input string. // Update input string.
g_free ( *input ); g_free ( *input );
*input = g_strdup ( state.text->text ); *input = g_strdup ( state.text->text );
@ -1438,18 +1371,12 @@ void error_dialog ( const char *msg, int markup )
main_window = create_window ( display ); main_window = create_window ( display );
} }
menu_calculate_window_and_element_width ( &state, &mon ); menu_calculate_window_and_element_width ( &state, &mon );
state.max_elements = 0; state.max_elements = 0;
state.text = state.text = textbox_create ( main_window, &vinfo, map, TB_AUTOHEIGHT + ( ( markup ) ? TB_MARKUP : 0 ),
textbox_create ( main_window, &vinfo, map, TB_AUTOHEIGHT + ( ( markup ) ? TB_MARKUP : 0 ), ( config.padding ), ( config.padding ),
( config.padding ), ( state.w - ( 2 * ( config.padding ) ) ), 1, NORMAL, ( msg != NULL ) ? msg : "" );
( config.padding ),
( state.w - ( 2 * ( config.padding ) ) ),
1,
NORMAL,
( msg != NULL ) ? msg : "" );
textbox_show ( state.text ); textbox_show ( state.text );
state.line_height = textbox_get_height ( state.text ); state.line_height = textbox_get_height ( state.text );
@ -1632,7 +1559,6 @@ static void handle_keypress ( XEvent *ev )
} }
} }
/** /**
* Help function. This calls man. * Help function. This calls man.
*/ */
@ -1645,7 +1571,6 @@ static void help ()
} }
} }
/** /**
* Function bound by 'atexit'. * Function bound by 'atexit'.
* Cleanup globally allocated memory. * Cleanup globally allocated memory.
@ -1676,7 +1601,6 @@ static void cleanup ()
display = NULL; display = NULL;
} }
// Cleaning up memory allocated by the Xresources file. // Cleaning up memory allocated by the Xresources file.
config_xresource_free (); config_xresource_free ();
for ( unsigned int i = 0; i < num_switchers; i++ ) { for ( unsigned int i = 0; i < num_switchers; i++ ) {
@ -1709,12 +1633,9 @@ static void setup_switchers ( void )
// Make a copy, as strtok will modify it. // Make a copy, as strtok will modify it.
char *switcher_str = g_strdup ( config.switchers ); char *switcher_str = g_strdup ( config.switchers );
// Split token on ','. This modifies switcher_str. // Split token on ','. This modifies switcher_str.
for ( char *token = strtok_r ( switcher_str, ",", &savept ); for ( char *token = strtok_r ( switcher_str, ",", &savept ); token != NULL; token = strtok_r ( NULL, ",", &savept ) ) {
token != NULL;
token = strtok_r ( NULL, ",", &savept ) ) {
// Resize and add entry. // Resize and add entry.
switchers = switchers = (Mode *) g_realloc ( switchers, sizeof ( Mode ) * ( num_switchers + 1 ) );
(Mode *) g_realloc ( switchers, sizeof ( Mode ) * ( num_switchers + 1 ) );
switchers[num_switchers].tb = NULL; switchers[num_switchers].tb = NULL;
// Window switcher. // Window switcher.
@ -1765,9 +1686,7 @@ static void setup_switchers ( void )
// and re-alloc moves that pointer. // and re-alloc moves that pointer.
for ( unsigned int i = 0; i < num_switchers; i++ ) { for ( unsigned int i = 0; i < num_switchers; i++ ) {
switchers[i].sw->keycfg = g_strdup_printf ( "key-%s", switchers[i].sw->name ); switchers[i].sw->keycfg = g_strdup_printf ( "key-%s", switchers[i].sw->name );
config_parser_add_option ( xrm_String, config_parser_add_option ( xrm_String, switchers[i].sw->keycfg, (void * *) &( switchers[i].sw->keystr ) );
switchers[i].sw->keycfg,
(void * *) &( switchers[i].sw->keystr ) );
} }
} }
@ -1791,7 +1710,6 @@ static inline void load_configuration_dynamic ( Display *display )
config_parse_cmd_options_dynamic ( ); config_parse_cmd_options_dynamic ( );
} }
static void release_global_keybindings () static void release_global_keybindings ()
{ {
for ( unsigned int i = 0; i < num_switchers; i++ ) { for ( unsigned int i = 0; i < num_switchers; i++ ) {
@ -1823,12 +1741,10 @@ static void print_global_keybindings ()
fprintf ( stdout, "listening to the following keys:\n" ); fprintf ( stdout, "listening to the following keys:\n" );
for ( unsigned int i = 0; i < num_switchers; i++ ) { for ( unsigned int i = 0; i < num_switchers; i++ ) {
if ( switchers[i].sw->keystr != NULL ) { if ( switchers[i].sw->keystr != NULL ) {
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on %s\n", fprintf ( stdout, "\t* "color_bold "%s"color_reset " on %s\n", switchers[i].sw->name, switchers[i].sw->keystr );
switchers[i].sw->name, switchers[i].sw->keystr );
} }
else { else {
fprintf ( stdout, "\t* "color_bold "%s"color_reset " on <unspecified>\n", fprintf ( stdout, "\t* "color_bold "%s"color_reset " on <unspecified>\n", switchers[i].sw->name );
switchers[i].sw->name );
} }
} }
} }
@ -1849,9 +1765,7 @@ static void reload_configuration ()
XCloseDisplay ( temp_display ); XCloseDisplay ( temp_display );
} }
else { else {
fprintf ( fprintf ( stderr, "Failed to get a new connection to the X11 server. No point in continuing.\n" );
stderr,
"Failed to get a new connection to the X11 server. No point in continuing.\n" );
abort (); abort ();
} }
} }
@ -1968,7 +1882,6 @@ static int main_loop_signal_handler ( char command, int quiet )
return FALSE; return FALSE;
} }
/** /**
* Setup signal handling. * Setup signal handling.
* Block all the signals, start a signal processor thread to handle these events. * Block all the signals, start a signal processor thread to handle these events.
@ -2160,7 +2073,6 @@ int main ( int argc, char *argv[] )
print_global_keybindings (); print_global_keybindings ();
} }
// Create a pipe to communicate between signal thread an main thread. // Create a pipe to communicate between signal thread an main thread.
int pfds[2]; int pfds[2];
if ( pipe ( pfds ) != 0 ) { if ( pipe ( pfds ) != 0 ) {
@ -2224,7 +2136,6 @@ int main ( int argc, char *argv[] )
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
SwitcherMode switcher_run ( char **input, Switcher *sw ) SwitcherMode switcher_run ( char **input, Switcher *sw )
{ {
char *prompt = g_strdup_printf ( "%s:", sw->name ); char *prompt = g_strdup_printf ( "%s:", sw->name );

View file

@ -35,7 +35,6 @@
#include <X11/Xft/Xft.h> #include <X11/Xft/Xft.h>
#include <ctype.h> #include <ctype.h>
#include "rofi.h" #include "rofi.h"
#include "textbox.h" #include "textbox.h"
#include "keyb.h" #include "keyb.h"
@ -51,7 +50,6 @@ extern Display *display;
XVisualInfo *visual_info; XVisualInfo *visual_info;
Colormap target_colormap; Colormap target_colormap;
typedef struct _RowColor typedef struct _RowColor
{ {
XftColor fg; XftColor fg;
@ -64,18 +62,11 @@ typedef struct _RowColor
#define num_states 3 #define num_states 3
RowColor colors[num_states]; RowColor colors[num_states];
PangoContext *p_context = NULL; PangoContext *p_context = NULL;
// Xft text box, optionally editable // Xft text box, optionally editable
textbox* textbox_create ( Window parent, textbox* textbox_create ( Window parent, XVisualInfo *vinfo, Colormap map, TextboxFlags flags, short x, short y, short w, short h,
XVisualInfo *vinfo, TextBoxFontType tbft, const char *text )
Colormap map,
TextboxFlags flags,
short x, short y, short w, short h,
TextBoxFontType tbft,
const char *text )
{ {
textbox *tb = g_malloc0 ( sizeof ( textbox ) ); textbox *tb = g_malloc0 ( sizeof ( textbox ) );
@ -133,8 +124,6 @@ textbox* textbox_create ( Window parent,
// auto height/width modes get handled here // auto height/width modes get handled here
textbox_moveresize ( tb, tb->x, tb->y, tb->w, tb->h ); textbox_moveresize ( tb, tb->x, tb->y, tb->w, tb->h );
// edit mode controls // edit mode controls
if ( tb->flags & TB_EDITABLE ) { if ( tb->flags & TB_EDITABLE ) {
tb->xim = XOpenIM ( display, NULL, NULL, NULL ); tb->xim = XOpenIM ( display, NULL, NULL, NULL );
@ -194,7 +183,6 @@ void textbox_text ( textbox *tb, const char *text )
textbox_moveresize ( tb, tb->x, tb->y, tb->w, tb->h ); textbox_moveresize ( tb, tb->x, tb->y, tb->w, tb->h );
} }
tb->cursor = MAX ( 0, MIN ( ( int ) strlen ( text ), tb->cursor ) ); tb->cursor = MAX ( 0, MIN ( ( int ) strlen ( text ), tb->cursor ) );
} }
// set the default text to display // set the default text to display
@ -220,7 +208,6 @@ void textbox_text_markup ( textbox *tb, const char *text )
textbox_moveresize ( tb, tb->x, tb->y, tb->w, tb->h ); textbox_moveresize ( tb, tb->x, tb->y, tb->w, tb->h );
} }
tb->cursor = MAX ( 0, MIN ( ( int ) strlen ( text ), tb->cursor ) ); tb->cursor = MAX ( 0, MIN ( ( int ) strlen ( text ), tb->cursor ) );
} }
@ -281,7 +268,6 @@ void textbox_hide ( textbox *tb )
XUnmapWindow ( display, tb->window ); XUnmapWindow ( display, tb->window );
} }
// will also unmap the window if still displayed // will also unmap the window if still displayed
void textbox_free ( textbox *tb ) void textbox_free ( textbox *tb )
{ {
@ -337,9 +323,6 @@ void textbox_draw ( textbox *tb )
cursor_x = pos.x / PANGO_SCALE; cursor_x = pos.x / PANGO_SCALE;
} }
// pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->w - 2 * SIDE_MARGIN ) );
// Skip the side MARGIN on the X axis. // Skip the side MARGIN on the X axis.
int x = PANGO_SCALE * SIDE_MARGIN; int x = PANGO_SCALE * SIDE_MARGIN;
int y = 0; int y = 0;
@ -576,7 +559,6 @@ int textbox_keypress ( textbox *tb, XEvent *ev )
return 0; return 0;
} }
if ( !( tb->flags & TB_EDITABLE ) ) { if ( !( tb->flags & TB_EDITABLE ) ) {
return 0; return 0;
} }
@ -656,8 +638,6 @@ int textbox_keypress ( textbox *tb, XEvent *ev )
return 0; return 0;
} }
/*** /***
* Font setup. * Font setup.
*/ */

View file

@ -59,17 +59,14 @@ const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
unsigned int NumlockMask = 0; unsigned int NumlockMask = 0;
// retrieve a property of any type from a window // retrieve a property of any type from a window
int window_get_prop ( Display *display, Window w, Atom prop, int window_get_prop ( Display *display, Window w, Atom prop, Atom *type, int *items, void *buffer, unsigned int bytes )
Atom *type, int *items,
void *buffer, unsigned int bytes )
{ {
int format; int format;
unsigned long nitems, nbytes; unsigned long nitems, nbytes;
unsigned char *ret = NULL; unsigned char *ret = NULL;
memset ( buffer, 0, bytes ); memset ( buffer, 0, bytes );
if ( XGetWindowProperty ( display, w, prop, 0, bytes / 4, False, AnyPropertyType, type, if ( XGetWindowProperty ( display, w, prop, 0, bytes / 4, False, AnyPropertyType, type, &format, &nitems, &nbytes,
&format, &nitems, &nbytes,
&ret ) == Success && ret && *type != None && format ) { &ret ) == Success && ret && *type != None && format ) {
if ( format == 8 ) { if ( format == 8 ) {
memmove ( buffer, ret, MIN ( bytes, nitems ) ); memmove ( buffer, ret, MIN ( bytes, nitems ) );
@ -109,8 +106,7 @@ char* window_get_text_prop ( Display *display, Window w, Atom atom )
g_strlcpy ( res, ( char * ) prop.value, l ); g_strlcpy ( res, ( char * ) prop.value, l );
} }
} }
else if ( Xutf8TextPropertyToTextList ( display, &prop, &list, else if ( Xutf8TextPropertyToTextList ( display, &prop, &list, &count ) >= Success && count > 0 && *list ) {
&count ) >= Success && count > 0 && *list ) {
size_t l = strlen ( *list ) + 1; size_t l = strlen ( *list ) + 1;
res = g_malloc ( l ); res = g_malloc ( l );
// make clang-check happy. // make clang-check happy.
@ -131,25 +127,20 @@ int window_get_atom_prop ( Display *display, Window w, Atom atom, Atom *list, in
{ {
Atom type; Atom type;
int items; int items;
return window_get_prop ( display, w, atom, &type, &items, list, return window_get_prop ( display, w, atom, &type, &items, list, count * sizeof ( Atom ) ) && type == XA_ATOM ? items : 0;
count * sizeof ( Atom ) ) && type == XA_ATOM ? items : 0;
} }
void window_set_atom_prop ( Display *display, Window w, Atom prop, Atom *atoms, int count ) void window_set_atom_prop ( Display *display, Window w, Atom prop, Atom *atoms, int count )
{ {
XChangeProperty ( display, w, prop, XA_ATOM, 32, PropModeReplace, ( unsigned char * ) atoms, XChangeProperty ( display, w, prop, XA_ATOM, 32, PropModeReplace, ( unsigned char * ) atoms, count );
count );
} }
int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list, int window_get_cardinal_prop ( Display *display, Window w, Atom atom, unsigned long *list, int count )
int count )
{ {
Atom type; int items; Atom type; int items;
return window_get_prop ( display, w, atom, &type, &items, list, count * return window_get_prop ( display, w, atom, &type, &items, list, count * sizeof ( unsigned long ) ) && type == XA_CARDINAL ? items : 0;
sizeof ( unsigned long ) ) && type == XA_CARDINAL ? items : 0;
} }
int monitor_get_dimension ( Display *display, Screen *screen, int monitor, workarea *mon ) int monitor_get_dimension ( Display *display, Screen *screen, int monitor, workarea *mon )
{ {
memset ( mon, 0, sizeof ( workarea ) ); memset ( mon, 0, sizeof ( workarea ) );
@ -187,8 +178,7 @@ void monitor_dimensions ( Display *display, Screen *screen, int x, int y, workar
if ( info ) { if ( info ) {
for ( int i = 0; i < monitors; i++ ) { for ( int i = 0; i < monitors; i++ ) {
if ( INTERSECT ( x, y, 1, 1, info[i].x_org, info[i].y_org, info[i].width, if ( INTERSECT ( x, y, 1, 1, info[i].x_org, info[i].y_org, info[i].width, info[i].height ) ) {
info[i].height ) ) {
mon->x = info[i].x_org; mon->x = info[i].x_org;
mon->y = info[i].y_org; mon->y = info[i].y_org;
mon->w = info[i].width; mon->w = info[i].width;
@ -227,7 +217,6 @@ static int pointer_get ( Display *display, Window root, int *x, int *y )
return 0; return 0;
} }
// determine which monitor holds the active window, or failing that the mouse pointer // determine which monitor holds the active window, or failing that the mouse pointer
void monitor_active ( Display *display, workarea *mon ) void monitor_active ( Display *display, workarea *mon )
{ {
@ -244,16 +233,12 @@ void monitor_active ( Display *display, workarea *mon )
} }
fprintf ( stderr, "Failed to find selected monitor.\n" ); fprintf ( stderr, "Failed to find selected monitor.\n" );
} }
if ( window_get_prop ( display, root, netatoms[_NET_ACTIVE_WINDOW], &type, &count, &id, if ( window_get_prop ( display, root, netatoms[_NET_ACTIVE_WINDOW], &type, &count, &id, sizeof ( Window ) )
sizeof ( Window ) )
&& type == XA_WINDOW && count > 0 ) { && type == XA_WINDOW && count > 0 ) {
XWindowAttributes attr; XWindowAttributes attr;
if ( XGetWindowAttributes ( display, id, &attr ) ) { if ( XGetWindowAttributes ( display, id, &attr ) ) {
Window junkwin; Window junkwin;
if ( XTranslateCoordinates ( display, id, attr.root, if ( XTranslateCoordinates ( display, id, attr.root, -attr.border_width, -attr.border_width, &x, &y, &junkwin ) == True ) {
-attr.border_width,
-attr.border_width,
&x, &y, &junkwin ) == True ) {
if ( config.monitor == -2 ) { if ( config.monitor == -2 ) {
// place the menu above the window // place the menu above the window
// if some window is focused, place menu above window, else fall // if some window is focused, place menu above window, else fall
@ -281,9 +266,7 @@ void monitor_active ( Display *display, workarea *mon )
monitor_dimensions ( display, screen, 0, 0, mon ); monitor_dimensions ( display, screen, 0, 0, mon );
} }
int window_send_message ( Display *display, Window target, int window_send_message ( Display *display, Window trg, Window subject, Atom atom, unsigned long protocol, unsigned long mask, Time time )
Window subject, Atom atom,
unsigned long protocol, unsigned long mask, Time time )
{ {
XEvent e; XEvent e;
memset ( &e, 0, sizeof ( XEvent ) ); memset ( &e, 0, sizeof ( XEvent ) );
@ -294,7 +277,7 @@ int window_send_message ( Display *display, Window target,
e.xclient.data.l[1] = time; e.xclient.data.l[1] = time;
e.xclient.send_event = True; e.xclient.send_event = True;
e.xclient.format = 32; e.xclient.format = 32;
int r = XSendEvent ( display, target, False, mask, &e ) ? 1 : 0; int r = XSendEvent ( display, trg, False, mask, &e ) ? 1 : 0;
XFlush ( display ); XFlush ( display );
return r; return r;
} }
@ -334,10 +317,8 @@ void x11_grab_key ( Display *display, unsigned int modmask, KeySym key )
XGrabKey ( display, keycode, modmask | LockMask, root, True, GrabModeAsync, GrabModeAsync ); XGrabKey ( display, keycode, modmask | LockMask, root, True, GrabModeAsync, GrabModeAsync );
if ( NumlockMask ) { if ( NumlockMask ) {
XGrabKey ( display, keycode, modmask | NumlockMask, root, True, GrabModeAsync, XGrabKey ( display, keycode, modmask | NumlockMask, root, True, GrabModeAsync, GrabModeAsync );
GrabModeAsync ); XGrabKey ( display, keycode, modmask | NumlockMask | LockMask, root, True, GrabModeAsync, GrabModeAsync );
XGrabKey ( display, keycode, modmask | NumlockMask | LockMask, root, True, GrabModeAsync,
GrabModeAsync );
} }
} }
@ -437,8 +418,7 @@ void x11_set_window_opacity ( Display *display, Window box, unsigned int opacity
// Scale 0-100 to 0 - UINT32_MAX. // Scale 0-100 to 0 - UINT32_MAX.
unsigned int opacity_set = ( unsigned int ) ( ( opacity / 100.0 ) * UINT32_MAX ); unsigned int opacity_set = ( unsigned int ) ( ( opacity / 100.0 ) * UINT32_MAX );
// Set opacity. // Set opacity.
XChangeProperty ( display, box, netatoms[_NET_WM_WINDOW_OPACITY], XChangeProperty ( display, box, netatoms[_NET_WM_WINDOW_OPACITY], XA_CARDINAL, 32, PropModeReplace,
XA_CARDINAL, 32, PropModeReplace,
( unsigned char * ) &opacity_set, 1L ); ( unsigned char * ) &opacity_set, 1L );
} }
@ -455,7 +435,6 @@ static void x11_create_frequently_used_atoms ( Display *display )
} }
} }
static int ( *xerror )( Display *, XErrorEvent * ); static int ( *xerror )( Display *, XErrorEvent * );
/** /**
* @param d The connection to the X server. * @param d The connection to the X server.
@ -467,8 +446,7 @@ static int display_oops ( Display *d, XErrorEvent *ee )
{ {
if ( ee->error_code == BadWindow if ( ee->error_code == BadWindow
|| ( ee->request_code == X_GrabButton && ee->error_code == BadAccess ) || ( ee->request_code == X_GrabButton && ee->error_code == BadAccess )
|| ( ee->request_code == X_GrabKey && ee->error_code == BadAccess ) || ( ee->request_code == X_GrabKey && ee->error_code == BadAccess )) {
) {
return 0; return 0;
} }
@ -488,8 +466,6 @@ void x11_setup ( Display *display )
x11_create_frequently_used_atoms ( display ); x11_create_frequently_used_atoms ( display );
} }
extern Colormap map; extern Colormap map;
extern XVisualInfo vinfo; extern XVisualInfo vinfo;
int truecolor = FALSE; int truecolor = FALSE;
@ -499,8 +475,7 @@ void create_visual_and_colormap ( Display *display )
// Try to create TrueColor map // Try to create TrueColor map
if ( XMatchVisualInfo ( display, screen, 32, TrueColor, &vinfo ) ) { if ( XMatchVisualInfo ( display, screen, 32, TrueColor, &vinfo ) ) {
// Visual found, lets try to create map. // Visual found, lets try to create map.
map = XCreateColormap ( display, DefaultRootWindow ( map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone );
display ), vinfo.visual, AllocNone );
truecolor = TRUE; truecolor = TRUE;
} }
// Failed to create map. // Failed to create map.

View file

@ -6,7 +6,6 @@
#include <history.h> #include <history.h>
#include <string.h> #include <string.h>
static int test = 0; static int test = 0;
#define TASSERT( a ) { \ #define TASSERT( a ) { \

View file

@ -12,7 +12,6 @@
#include <textbox.h> #include <textbox.h>
#include <rofi.h> #include <rofi.h>
static int test = 0; static int test = 0;
unsigned int normal_window_mode = 0; unsigned int normal_window_mode = 0;
@ -158,7 +157,6 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
TASSERT ( strcmp ( box->text, "aapmies" ) == 0 ); TASSERT ( strcmp ( box->text, "aapmies" ) == 0 );
TASSERT ( box->cursor == 5 ); TASSERT ( box->cursor == 5 );
textbox_font ( box, HIGHLIGHT ); textbox_font ( box, HIGHLIGHT );
textbox_draw ( box ); textbox_draw ( box );