summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/config.c36
-rw-r--r--include/rofi.h112
-rw-r--r--include/textbox.h60
-rw-r--r--include/xrmoptions.h2
-rw-r--r--source/dmenu-dialog.c52
-rw-r--r--source/rofi.c1830
-rw-r--r--source/run-dialog.c361
-rw-r--r--source/ssh-dialog.c313
-rw-r--r--source/textbox.c401
-rw-r--r--source/xrmoptions.c75
10 files changed, 1910 insertions, 1332 deletions
diff --git a/config/config.c b/config/config.c
index ec8cdb69..4950dba5 100644
--- a/config/config.c
+++ b/config/config.c
@@ -30,41 +30,41 @@ Settings config = {
// Set the default window opacity.
// This option only works when running a composite manager.
// -o
- .window_opacity = 100,
+ .window_opacity = 100,
// Border width around the window.
- .menu_bw = 1,
+ .menu_bw = 1,
// The width of the switcher. (0-100 in % > 100 in pixels)
- .menu_width = 50,
+ .menu_width = 50,
// Maximum number of options to show.
- .menu_lines = 15,
+ .menu_lines = 15,
// Font
- .menu_font = "mono-12",
+ .menu_font = "mono-12",
// Foreground color
- .menu_fg = "#222222",
+ .menu_fg = "#222222",
// Background color
- .menu_bg = "#f2f1f0",
+ .menu_bg = "#f2f1f0",
// Foreground color (selected)
- .menu_hlfg = "#ffffff",
+ .menu_hlfg = "#ffffff",
// Background color (selected)
- .menu_hlbg = "#005577",
+ .menu_hlbg = "#005577",
// Border color.
- .menu_bc = "black",
+ .menu_bc = "black",
// Directly select when only 1 choice is left
- .zeltak_mode = 0,
+ .zeltak_mode = 0,
// Terminal to use. (for ssh and open in terminal)
.terminal_emulator = "x-terminal-emulator",
#ifdef I3
// Auto-detected. no longer used.
- .i3_mode = 0,
+ .i3_mode = 0,
#endif
// Key binding
- .window_key = "F12",
- .run_key = "mod1+F2",
- .ssh_key = "mod1+F3",
+ .window_key = "F12",
+ .run_key = "mod1+F2",
+ .ssh_key = "mod1+F3",
// Location of the window. WL_CENTER, WL_NORTH_WEST, WL_NORTH,WL_NORTH_EAST, etc.
- .location = WL_CENTER,
+ .location = WL_CENTER,
// Mode of window, list (Vertical) or dmenu like (Horizontal)
- .wmode = VERTICAL,
+ .wmode = VERTICAL,
// Padding of the window.
- .padding = 5
+ .padding = 5
};
diff --git a/include/rofi.h b/include/rofi.h
index 6e6f1310..01e164a3 100644
--- a/include/rofi.h
+++ b/include/rofi.h
@@ -3,18 +3,19 @@
#include <config.h>
#include <X11/X.h>
-#define MAX(a, b) ((a) > (b) ? (a) : (b))
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#define NEAR(a,o,b) ((b) > (a)-(o) && (b) < (a)+(o))
-#define OVERLAP(a,b,c,d) (((a)==(c) && (b)==(d)) || MIN((a)+(b), (c)+(d)) - MAX((a), (c)) > 0)
-#define INTERSECT(x,y,w,h,x1,y1,w1,h1) (OVERLAP((x),(w),(x1),(w1)) && OVERLAP((y),(h),(y1),(h1)))
+#define MAX( a, b ) ( ( a ) > ( b ) ? ( a ) : ( b ) )
+#define MIN( a, b ) ( ( a ) < ( b ) ? ( a ) : ( b ) )
+#define NEAR( a, o, b ) ( ( b ) > ( a ) - ( o ) && ( b ) < ( a ) + ( o ) )
+#define OVERLAP( a, b, c, d ) ( ( ( a ) == ( c ) && ( b ) == ( d ) ) || MIN ( ( a ) + ( b ), ( c ) + ( d ) ) - MAX ( ( a ), ( c ) ) > 0 )
+#define INTERSECT( x, y, w, h, x1, y1, w1, h1 ) ( OVERLAP ( ( x ), ( w ), ( x1 ), ( w1 ) ) && OVERLAP ( ( y ), ( h ), ( y1 ), ( h1 ) ) )
extern const char *cache_dir;
#ifdef HAVE_I3_IPC_H
-extern char *i3_socket_path;
+extern char *i3_socket_path;
#endif
-typedef enum {
+typedef enum
+{
WINDOW_SWITCHER,
RUN_DIALOG,
SSH_DIALOG,
@@ -24,46 +25,48 @@ typedef enum {
NEXT_DIALOG
} SwitcherMode;
-typedef enum {
- MENU_OK = 0,
+typedef enum
+{
+ MENU_OK = 0,
MENU_CANCEL = -1,
MENU_NEXT = -2,
MENU_CUSTOM_INPUT = -3,
MENU_ENTRY_DELETE = -4
-
} MenuReturn;
typedef int ( *menu_match_cb )( char **tokens, const char *input, int index, void *data );
-MenuReturn menu( char **lines, char **input, char *prompt,
- Time *time, int *shift,
- menu_match_cb mmc, void *mmc_data,
- int *selected_line );
+MenuReturn menu ( char **lines, char **input, char *prompt,
+ Time *time, int *shift,
+ menu_match_cb mmc, void *mmc_data,
+ int *selected_line );
/**
* Allocator wrappers
*/
-void* allocate( unsigned long bytes ) __attribute__((malloc));
-void* allocate_clear( unsigned long bytes );
-void* reallocate( void *ptr, unsigned long bytes );
-
-
-void catch_exit( __attribute__( ( unused ) ) int sig );
-
-typedef enum _WindowLocation {
- WL_CENTER = 0,
- WL_NORTH_WEST = 1,
- WL_NORTH = 2,
- WL_NORTH_EAST = 3,
- WL_EAST = 4,
- WL_EAST_SOUTH = 5,
- WL_SOUTH = 6,
- WL_SOUTH_WEST = 7,
- WL_WEST = 8
+void* allocate ( unsigned long bytes ) __attribute__( ( malloc ) );
+void* allocate_clear ( unsigned long bytes );
+void* reallocate ( void *ptr, unsigned long bytes );
+
+
+void catch_exit ( __attribute__( ( unused ) ) int sig );
+
+typedef enum _WindowLocation
+{
+ WL_CENTER = 0,
+ WL_NORTH_WEST = 1,
+ WL_NORTH = 2,
+ WL_NORTH_EAST = 3,
+ WL_EAST = 4,
+ WL_EAST_SOUTH = 5,
+ WL_SOUTH = 6,
+ WL_SOUTH_WEST = 7,
+ WL_WEST = 8
} WindowLocation;
-typedef enum {
+typedef enum
+{
VERTICAL = 0,
HORIZONTAL = 1
} WindowMode;
@@ -71,38 +74,39 @@ typedef enum {
* Settings
*/
-typedef struct _Settings {
+typedef struct _Settings
+{
// Window settings
- unsigned int window_opacity;
+ unsigned int window_opacity;
// Menu settings
- unsigned int menu_bw;
- unsigned int menu_width;
- unsigned int menu_lines;
- char * menu_font;
- char * menu_fg;
- char * menu_bg;
- char * menu_hlfg;
- char * menu_hlbg;
- char * menu_bc;
+ unsigned int menu_bw;
+ unsigned int menu_width;
+ unsigned int menu_lines;
+ char * menu_font;
+ char * menu_fg;
+ char * menu_bg;
+ char * menu_hlfg;
+ char * menu_hlbg;
+ char * menu_bc;
// Behavior
- unsigned int zeltak_mode;
- char * terminal_emulator;
+ unsigned int zeltak_mode;
+ char * terminal_emulator;
#ifdef HAVE_I3_IPC_H
- unsigned int i3_mode;
+ unsigned int i3_mode;
#endif
// Key bindings
- char * window_key;
- char * run_key;
- char * ssh_key;
- WindowLocation location;
- WindowMode wmode;
- unsigned int padding;
+ char * window_key;
+ char * run_key;
+ char * ssh_key;
+ WindowLocation location;
+ WindowMode wmode;
+ unsigned int padding;
} Settings;
extern Settings config;
int token_match ( char **tokens, const char *input,
- __attribute__( ( unused ) )int index,
- __attribute__( ( unused ) )void *data );
+ __attribute__( ( unused ) ) int index,
+ __attribute__( ( unused ) ) void *data );
#endif
diff --git a/include/textbox.h b/include/textbox.h
index 4e4061b1..7fbc3a0e 100644
--- a/include/textbox.h
+++ b/include/textbox.h
@@ -1,47 +1,49 @@
#ifndef __TEXTBOX_H__
#define __TEXTBOX_H__
-typedef struct {
+typedef struct
+{
unsigned long flags;
- Window window, parent;
- short x, y, w, h;
- short cursor;
- XftFont *font;
- XftColor color_fg, color_bg;
- char *text, *prompt;
- XIM xim;
- XIC xic;
- XGlyphInfo extents;
+ Window window, parent;
+ short x, y, w, h;
+ short cursor;
+ XftFont *font;
+ XftColor color_fg, color_bg;
+ char *text, *prompt;
+ XIM xim;
+ XIC xic;
+ XGlyphInfo extents;
} textbox;
-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,
+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,
} TextboxFlags;
-textbox* textbox_create( Window parent,
- TextboxFlags flags,
- short x, short y, short w, short h,
- char *font, char *fg, char *bg,
- char *text, char *prompt );
+textbox* textbox_create ( Window parent,
+ TextboxFlags flags,
+ short x, short y, short w, short h,
+ char *font, char *fg, char *bg,
+ char *text, char *prompt );
-void textbox_free( textbox *tb );
+void textbox_free ( textbox *tb );
-void textbox_font( textbox *tb, char *font, char *fg, char *bg );
+void textbox_font ( textbox *tb, char *font, char *fg, char *bg );
-void textbox_text( textbox *tb, char *text );
-void textbox_show( textbox *tb );
-void textbox_draw( textbox *tb );
+void textbox_text ( textbox *tb, char *text );
+void textbox_show ( textbox *tb );
+void textbox_draw ( textbox *tb );
-int textbox_keypress( textbox *tb, XEvent *ev );
+int textbox_keypress ( textbox *tb, XEvent *ev );
-void textbox_cursor_end( textbox *tb );
+void textbox_cursor_end ( textbox *tb );
#endif //__TEXTBOX_H__
diff --git a/include/xrmoptions.h b/include/xrmoptions.h
index e46ba11a..7fa8a522 100644
--- a/include/xrmoptions.h
+++ b/include/xrmoptions.h
@@ -1,5 +1,5 @@
#ifndef __XRMOPTIONS_H__
#define __XRMOPTIONS_H__
-void parse_xresource_options( Display *display );
+void parse_xresource_options ( Display *display );
#endif
diff --git a/source/dmenu-dialog.c b/source/dmenu-dialog.c
index 49a70fe1..939a24cb 100644
--- a/source/dmenu-dialog.c
+++ b/source/dmenu-dialog.c
@@ -42,16 +42,19 @@ static char **get_dmenu ( )
{
char buffer[1024];
char **retv = NULL;
- int index = 0;
+ int index = 0;
- while ( fgets( buffer, 1024, stdin ) != NULL ) {
- retv = reallocate( retv, ( index+2 )*sizeof( char* ) );
- retv[index] = strdup( buffer );
- retv[index+1] = NULL;
+ while ( fgets ( buffer, 1024, stdin ) != NULL )
+ {
+ retv = reallocate ( retv, ( index + 2 ) * sizeof ( char* ) );
+ retv[index] = strdup ( buffer );
+ retv[index + 1] = NULL;
// Filter out line-end.
- if ( retv[index][strlen( buffer )-1] == '\n' )
- retv[index][strlen( buffer )-1] = '\0';
+ if ( retv[index][strlen ( buffer ) - 1] == '\n' )
+ {
+ retv[index][strlen ( buffer ) - 1] = '\0';
+ }
index++;
}
@@ -61,27 +64,36 @@ static char **get_dmenu ( )
SwitcherMode dmenu_switcher_dialog ( char **input )
{
- int selected_line = 0;
- SwitcherMode retv = MODE_EXIT;
+ int selected_line = 0;
+ SwitcherMode retv = MODE_EXIT;
// act as a launcher
- char **list = get_dmenu( );
+ char **list = get_dmenu ( );
- int mretv = menu( list, input, dmenu_prompt,NULL, NULL,
- token_match, NULL, &selected_line );
+ int mretv = menu ( list, input, dmenu_prompt, NULL, NULL,
+ token_match, NULL, &selected_line );
- if ( mretv == MENU_NEXT ) {
+ if ( mretv == MENU_NEXT )
+ {
retv = DMENU_DIALOG;
- } else if ( mretv == MENU_OK && list[selected_line] != NULL ) {
- fputs( list[selected_line],stdout );
- } else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) {
- fputs( *input, stdout );
+ }
+ else if ( mretv == MENU_OK && list[selected_line] != NULL )
+ {
+ fputs ( list[selected_line], stdout );
+ }
+ else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' )
+ {
+ fputs ( *input, stdout );
}
- for ( unsigned int i=0; list != NULL && list[i] != NULL; i++ ) {
- free( list[i] );
+ for ( unsigned int i = 0; list != NULL && list[i] != NULL; i++ )
+ {
+ free ( list[i] );
}
- if ( list != NULL ) free( list );
+ if ( list != NULL )
+ {
+ free ( list );
+ }
return retv;
}
diff --git a/source/rofi.c b/source/rofi.c
index edfd614c..a14fd1d7 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -70,16 +70,16 @@
#include "xrmoptions.h"
-#define LINE_MARGIN 4
+#define LINE_MARGIN 4
-#define OPAQUE 0xffffffff
-#define OPACITY "_NET_WM_WINDOW_OPACITY"
-#define I3_SOCKET_PATH_PROP "I3_SOCKET_PATH"
-#define FORK 1
-#define NOFORK 2
+#define OPAQUE 0xffffffff
+#define OPACITY "_NET_WM_WINDOW_OPACITY"
+#define I3_SOCKET_PATH_PROP "I3_SOCKET_PATH"
+#define FORK 1
+#define NOFORK 2
-xdgHandle xdg_handle;
+xdgHandle xdg_handle;
const char *cache_dir = NULL;
/**
@@ -87,336 +87,389 @@ const char *cache_dir = NULL;
* Matches tokenized.
*/
int token_match ( char **tokens, const char *input,
- __attribute__( ( unused ) )int index,
- __attribute__( ( unused ) )void *data )
+ __attribute__( ( unused ) ) int index,
+ __attribute__( ( unused ) ) void *data )
{
int match = 1;
// Do a tokenized match.
- if ( tokens ) for ( int j = 1; match && tokens[j]; j++ ) {
- match = ( strcasestr( input, tokens[j] ) != NULL );
+ if ( tokens )
+ {
+ for ( int j = 1; match && tokens[j]; j++ )
+ {
+ match = ( strcasestr ( input, tokens[j] ) != NULL );
}
+ }
return match;
}
-void* allocate( unsigned long bytes )
+void* allocate ( unsigned long bytes )
{
- if ( bytes == 0 ) return NULL;
+ if ( bytes == 0 )
+ {
+ return NULL;
+ }
- void *ptr = malloc( bytes );
+ void *ptr = malloc ( bytes );
- if ( !ptr ) {
- fprintf( stderr, "malloc failed!\n" );
- exit( EXIT_FAILURE );
+ if ( !ptr )
+ {
+ fprintf ( stderr, "malloc failed!\n" );
+ exit ( EXIT_FAILURE );
}
return ptr;
}
-void* allocate_clear( unsigned long bytes )
+void* allocate_clear ( unsigned long bytes )
{
- if ( bytes == 0 ) return NULL;
+ if ( bytes == 0 )
+ {
+ return NULL;
+ }
- void *ptr = allocate( bytes );
- memset( ptr, 0, bytes );
+ void *ptr = allocate ( bytes );
+ memset ( ptr, 0, bytes );
return ptr;
}
-void* reallocate( void *ptr, unsigned long bytes )
+void* reallocate ( void *ptr, unsigned long bytes )
{
- if ( bytes == 0 ) return NULL;
+ if ( bytes == 0 )
+ {
+ return NULL;
+ }
- ptr = realloc( ptr, bytes );
+ ptr = realloc ( ptr, bytes );
- if ( !ptr ) {
- fprintf( stderr, "realloc failed!\n" );
- exit( EXIT_FAILURE );
+ if ( !ptr )
+ {
+ fprintf ( stderr, "realloc failed!\n" );
+ exit ( EXIT_FAILURE );
}
return ptr;
}
-static char **tokenize( const char *input )
+static char **tokenize ( const char *input )
{
- if ( input == NULL ) return NULL;
+ if ( input == NULL )
+ {
+ return NULL;
+ }
char *saveptr = NULL, *token;
- char **retv = NULL;
+ char **retv = NULL;
// First entry is always full (modified) stringtext.
- int num_tokens = 1;
+ int num_tokens = 1;
//First entry is string that is modified.
- retv = allocate ( 2*sizeof( char* ) );
- retv[0] = strdup( input );
+ retv = allocate ( 2 * sizeof ( char* ) );
+ retv[0] = strdup ( input );
retv[1] = NULL;
// Iterate over tokens.
// strtok should still be valid for utf8.
for (
- token = strtok_r( retv[0], " ", &saveptr );
+ token = strtok_r ( retv[0], " ", &saveptr );
token != NULL;
- token = strtok_r( NULL, " ", &saveptr ) ) {
- retv = reallocate( retv, sizeof( char* )*( num_tokens+2 ) );
- retv[num_tokens+1] = NULL;
- retv[num_tokens] = token;
+ token = strtok_r ( NULL, " ", &saveptr ) )
+ {
+ retv = reallocate ( retv, sizeof ( char* ) * ( num_tokens + 2 ) );
+ retv[num_tokens + 1] = NULL;
+ retv[num_tokens] = token;
num_tokens++;
}
return retv;
}
-static inline void tokenize_free( char **ip )
+static inline void tokenize_free ( char **ip )
{
- if ( ip == NULL ) return;
+ if ( ip == NULL )
+ {
+ return;
+ }
if ( ip[0] )
- free( ip[0] );
+ {
+ free ( ip[0] );
+ }
- free( ip );
+ free ( ip );
}
#ifdef HAVE_I3_IPC_H
// Path to HAVE_I3_IPC_H socket.
char *i3_socket_path = NULL;
// Focus window on HAVE_I3_IPC_H window manager.
-static void focus_window_i3( const char *socket_path, int id )
+static void focus_window_i3 ( const char *socket_path, int id )
{
- i3_ipc_header_t head;
- char command[128];
- int s, t, len;
+ i3_ipc_header_t head;
+ char command[128];
+ int s, t, len;
struct sockaddr_un remote;
- if ( strlen( socket_path ) > UNIX_PATH_MAX ) {
- fprintf( stderr, "Socket path is to long. %zd > %d\n", strlen( socket_path ), UNIX_PATH_MAX );
+ if ( strlen ( socket_path ) > UNIX_PATH_MAX )
+ {
+ fprintf ( stderr, "Socket path is to long. %zd > %d\n", strlen ( socket_path ), UNIX_PATH_MAX );
return;
}
- if ( ( s = socket( AF_UNIX, SOCK_STREAM, 0 ) ) == -1 ) {
- fprintf( stderr, "Failed to open connection to I3: %s\n", strerror( errno ) );
+ if ( ( s = socket ( AF_UNIX, SOCK_STREAM, 0 ) ) == -1 )
+ {
+ fprintf ( stderr, "Failed to open connection to I3: %s\n", strerror ( errno ) );
return;
}
remote.sun_family = AF_UNIX;
- strcpy( remote.sun_path, socket_path );
- len = strlen( remote.sun_path ) + sizeof( remote.sun_family );
+ strcpy ( remote.sun_path, socket_path );
+ len = strlen ( remote.sun_path ) + sizeof ( remote.sun_family );
- if ( connect( s, ( struct sockaddr * )&remote, len ) == -1 ) {
- fprintf( stderr, "Failed to connect to I3 (%s): %s\n", socket_path,strerror( errno ) );
- close( s );
- return ;
+ if ( connect ( s, ( struct sockaddr * ) &remote, len ) == -1 )
+ {
+ fprintf ( stderr, "Failed to connect to I3 (%s): %s\n", socket_path, strerror ( errno ) );
+ close ( s );
+ return;
}
// Formulate command
- snprintf( command, 128, "[id=\"%d\"] focus", id );
+ snprintf ( command, 128, "[id=\"%d\"] focus", id );
// Prepare header.
- memcpy( head.magic, I3_IPC_MAGIC, 6 );
- head.size = strlen( command );
+ memcpy ( head.magic, I3_IPC_MAGIC, 6 );
+ head.size = strlen ( command );
head.type = I3_IPC_MESSAGE_TYPE_COMMAND;
// Send header.
- send( s, &head, sizeof( head ),0 );
+ send ( s, &head, sizeof ( head ), 0 );
// Send message
- send( s, command, strlen( command ),0 );
+ send ( s, command, strlen ( command ), 0 );
// Receive header.
- t = recv( s, &head, sizeof( head ),0 );
+ t = recv ( s, &head, sizeof ( head ), 0 );
- if ( t == sizeof( head ) ) {
- recv( s, command, head.size, 0 );
+ if ( t == sizeof ( head ) )
+ {
+ recv ( s, command, head.size, 0 );
}
- close( s );
+ close ( s );
}
#endif
-void catch_exit( __attribute__( ( unused ) ) int sig )
+void catch_exit ( __attribute__( ( unused ) ) int sig )
{
- while ( 0 < waitpid( -1, NULL, WNOHANG ) );
+ while ( 0 < waitpid ( -1, NULL, WNOHANG ) )
+ {
+ ;
+ }
}
// cli arg handling
-static int find_arg( const int argc, char * const argv[], const char * const key )
+static int find_arg ( const int argc, char * const argv[], const char * const key )
{
int i;
- for ( i = 0; i < argc && strcasecmp( argv[i], key ); i++ );
+ for ( i = 0; i < argc && strcasecmp ( argv[i], key ); i++ )
+ {
+ ;
+ }
- return i < argc ? i: -1;
+ return i < argc ? i : -1;
}
-static void find_arg_str( int argc, char *argv[], char *key, char** val )
+static void find_arg_str ( int argc, char *argv[], char *key, char** val )
{
- int i = find_arg( argc, argv, key );
+ int i = find_arg ( argc, argv, key );
- if ( val != NULL && i > 0 && i < argc-1 ) {
- *val = argv[i+1];
+ if ( val != NULL && i > 0 && i < argc - 1 )
+ {
+ *val = argv[i + 1];
}
}
static void find_arg_int ( int argc, char *argv[], char *key, unsigned int *val )
{
- int i = find_arg( argc, argv, key );
+ int i = find_arg ( argc, argv, key );
- if ( val != NULL && i > 0 && i < ( argc-1 ) ) {
- *val = strtol( argv[i+1], NULL, 10 );
+ if ( val != NULL && i > 0 && i < ( argc - 1 ) )
+ {
+ *val = strtol ( argv[i + 1], NULL, 10 );
}
}
unsigned int NumlockMask = 0;
-Display *display = NULL;
-Screen *screen;
-Window root;
-int screen_id;
-
-static int ( *xerror )( Display *, XErrorEvent * );
-
-#define ATOM_ENUM(x) x
-#define ATOM_CHAR(x) #x
-
-#define EWMH_ATOMS(X) \
-X(_NET_SUPPORTING_WM_CHECK),\
-X(_NET_CLIENT_LIST),\
-X(_NET_CLIENT_LIST_STACKING),\
-X(_NET_NUMBER_OF_DESKTOPS),\
-X(_NET_CURRENT_DESKTOP),\
-X(_NET_DESKTOP_GEOMETRY),\
-X(_NET_DESKTOP_VIEWPORT),\
-X(_NET_WORKAREA),\
-X(_NET_ACTIVE_WINDOW),\
-X(_NET_CLOSE_WINDOW),\
-X(_NET_MOVERESIZE_WINDOW),\
-X(_NET_WM_NAME),\
-X(_NET_WM_STATE),\
-X(_NET_WM_STATE_SKIP_TASKBAR),\
-X(_NET_WM_STATE_SKIP_PAGER),\
-X(_NET_WM_STATE_FULLSCREEN),\
-X(_NET_WM_STATE_ABOVE),\
-X(_NET_WM_STATE_BELOW),\
-X(_NET_WM_STATE_DEMANDS_ATTENTION),\
-X(_NET_WM_DESKTOP),\
-X(_NET_SUPPORTED)
-
-enum { EWMH_ATOMS( ATOM_ENUM ), NETATOMS };
-const char *netatom_names[] = { EWMH_ATOMS( ATOM_CHAR ) };
-Atom netatoms[NETATOMS];
+Display *display = NULL;
+Screen *screen;
+Window root;
+int screen_id;
+
+static int ( *xerror )( Display *, XErrorEvent * );
+
+#define ATOM_ENUM( x ) x
+#define ATOM_CHAR( x ) # x
+
+#define EWMH_ATOMS( X ) \
+ X ( _NET_SUPPORTING_WM_CHECK ), \
+ X ( _NET_CLIENT_LIST ), \
+ X ( _NET_CLIENT_LIST_STACKING ), \
+ X ( _NET_NUMBER_OF_DESKTOPS ), \
+ X ( _NET_CURRENT_DESKTOP ), \
+ X ( _NET_DESKTOP_GEOMETRY ), \
+ X ( _NET_DESKTOP_VIEWPORT ), \
+ X ( _NET_WORKAREA ), \
+ X ( _NET_ACTIVE_WINDOW ), \
+ X ( _NET_CLOSE_WINDOW ), \
+ X ( _NET_MOVERESIZE_WINDOW ), \
+ X ( _NET_WM_NAME ), \
+ X ( _NET_WM_STATE ), \
+ X ( _NET_WM_STATE_SKIP_TASKBAR ), \
+ X ( _NET_WM_STATE_SKIP_PAGER ), \
+ X ( _NET_WM_STATE_FULLSCREEN ), \
+ X ( _NET_WM_STATE_ABOVE ), \
+ X ( _NET_WM_STATE_BELOW ), \
+ X ( _NET_WM_STATE_DEMANDS_ATTENTION ), \
+ X ( _NET_WM_DESKTOP ), \
+ X ( _NET_SUPPORTED )
+
+enum { EWMH_ATOMS ( ATOM_ENUM ), NETATOMS };
+const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
+Atom netatoms[NETATOMS];
// X error handler
-int oops( __attribute__( ( unused ) ) Display *d, XErrorEvent *ee )
+int oops ( __attribute__( ( unused ) ) Display *d, XErrorEvent *ee )
{
if ( ee->error_code == BadWindow
|| ( ee->request_code == X_GrabButton && ee->error_code == BadAccess )
|| ( ee->request_code == X_GrabKey && ee->error_code == BadAccess )
- ) return 0;
+ )
+ {
+ return 0;
+ }
- fprintf( stderr, "error: request code=%d, error code=%d\n", ee->request_code, ee->error_code );
- return xerror( display, ee );
+ fprintf ( stderr, "error: request code=%d, error code=%d\n", ee->request_code, ee->error_code );
+ return xerror ( display, ee );
}
// usable space on a monitor
-typedef struct {
+typedef struct
+{
int x, y, w, h;
int l, r, t, b;
} workarea;
// window lists
-typedef struct {
+typedef struct
+{
Window *array;
- void **data;
- int len;
+ void **data;
+ int len;
} winlist;
winlist *cache_client;
winlist *cache_xattr;
-#define winlist_ascend(l,i,w) for ((i) = 0; (i) < (l)->len && (((w) = (l)->array[i]) || 1); (i)++)
-#define winlist_descend(l,i,w) for ((i) = (l)->len-1; (i) >= 0 && (((w) = (l)->array[i]) || 1); (i)--)
+#define winlist_ascend( l, i, w ) for ( ( i ) = 0; ( i ) < ( l )->len && ( ( ( w ) = ( l )->array[i] ) || 1 ); ( i )++ )
+#define winlist_descend( l, i, w ) for ( ( i ) = ( l )->len - 1; ( i ) >= 0 && ( ( ( w ) = ( l )->array[i] ) || 1 ); ( i )-- )
-#define WINLIST 32
+#define WINLIST 32
-winlist* winlist_new()
+winlist* winlist_new ()
{
- winlist *l = allocate( sizeof( winlist ) );
- l->len = 0;
- l->array = allocate( sizeof( Window ) * ( WINLIST+1 ) );
- l->data = allocate( sizeof( void* ) * ( WINLIST+1 ) );
+ winlist *l = allocate ( sizeof ( winlist ) );
+ l->len = 0;
+ l->array = allocate ( sizeof ( Window ) * ( WINLIST + 1 ) );
+ l->data = allocate ( sizeof ( void* ) * ( WINLIST + 1 ) );
return l;
}
-int winlist_append( winlist *l , Window w, void *d )
+int winlist_append ( winlist *l, Window w, void *d )
{
- if ( l->len > 0 && !( l->len % WINLIST ) ) {
- l->array = reallocate( l->array, sizeof( Window ) * ( l->len+WINLIST+1 ) );
- l->data = reallocate( l->data, sizeof( void* ) * ( l->len+WINLIST+1 ) );
+ if ( l->len > 0 && !( l->len % WINLIST ) )
+ {
+ l->array = reallocate ( l->array, sizeof ( Window ) * ( l->len + WINLIST + 1 ) );
+ l->data = reallocate ( l->data, sizeof ( void* ) * ( l->len + WINLIST + 1 ) );
}
// Make clang-check happy.
// TODO: make clang-check clear this should never be 0.
- if(l->data == NULL || l->array == NULL) return 0;
+ if ( l->data == NULL || l->array == NULL )
+ {
+ return 0;
+ }
- l->data[l->len] = d;
+ l->data[l->len] = d;
l->array[l->len++] = w;
- return l->len-1;
+ return l->len - 1;
}
-void winlist_empty( winlist *l )
+void winlist_empty ( winlist *l )
{
- while ( l->len > 0 ) free( l->data[--( l->len )] );
+ while ( l->len > 0 )
+ {
+ free ( l->data[--( l->len )] );
+ }
}
-void winlist_free( winlist *l )
+void winlist_free ( winlist *l )
{
- winlist_empty( l );
- free( l->array );
- free( l->data );
- free( l );
+ winlist_empty ( l );
+ free ( l->array );
+ free ( l->data );
+ free ( l );
}
-int winlist_find( winlist *l, Window w )
+int winlist_find ( winlist *l, Window w )
{
// iterate backwards. theory is: windows most often accessed will be
// nearer the end. testing with kcachegrind seems to support this...
- int i;
+ int i;
Window o = 0;
- winlist_descend( l, i, o ) if ( w == o ) return i;
+ winlist_descend ( l, i, o ) if ( w == o )
+ {
+ return i;
+ }
return -1;
}
-#define CLIENTTITLE 100
-#define CLIENTCLASS 50
-#define CLIENTNAME 50
-#define CLIENTSTATE 10
-#define CLIENTROLE 50
+#define CLIENTTITLE 100
+#define CLIENTCLASS 50
+#define CLIENTNAME 50
+#define CLIENTSTATE 10
+#define CLIENTROLE 50
// a managable window
-typedef struct {
- Window window, trans;
+typedef struct
+{
+ Window window, trans;
XWindowAttributes xattr;
- char title[CLIENTTITLE];
- char class[CLIENTCLASS];
- char name[CLIENTNAME];
- char role[CLIENTROLE];
- int states;
- Atom state[CLIENTSTATE];
- workarea monitor;
+ char title[CLIENTTITLE];
+ char class[CLIENTCLASS];
+ char name[CLIENTNAME];
+ char role[CLIENTROLE];
+ int states;
+ Atom state[CLIENTSTATE];
+ workarea monitor;
} client;
// allocate a pixel value for an X named color
-static unsigned int color_get( const char *const name )
+static unsigned int color_get ( const char *const name )
{
- XColor color;
- Colormap map = DefaultColormap( display, screen_id );
- return XAllocNamedColor( display, map, name, &color, &color ) ? color.pixel: None;
+ XColor color;
+ Colormap map = DefaultColormap ( display, screen_id );
+ return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None;
}
// find mouse pointer location
-int pointer_get( Window root, int *x, int *y )
+int pointer_get ( Window root, int *x, int *y )
{
*x = 0;
*y = 0;
- Window rr, cr;
- int rxr, ryr, wxr, wyr;
+ Window rr, cr;
+ int rxr, ryr, wxr, wyr;
unsigned int mr;
- if ( XQueryPointer( display, root, &rr, &cr, &rxr, &ryr, &wxr, &wyr, &mr ) ) {
+ if ( XQueryPointer ( display, root, &rr, &cr, &rxr, &ryr, &wxr, &wyr, &mr ) )
+ {
*x = rxr;
*y = ryr;
return 1;
@@ -425,40 +478,45 @@ int pointer_get( Window root, int *x, int *y )
return 0;
}
-int take_keyboard( Window w )
+int take_keyboard ( Window w )
{
int i;
- for ( i = 0; i < 1000; i++ ) {
- if ( XGrabKeyboard( display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime ) == GrabSuccess )
+ for ( i = 0; i < 1000; i++ )
+ {
+ if ( XGrabKeyboard ( display, w, True, GrabModeAsync, GrabModeAsync, CurrentTime ) ==