diff --git a/include/mark-dialog.h b/include/mark-dialog.h deleted file mode 100644 index 84227436..00000000 --- a/include/mark-dialog.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __MARK_DIALOG_H__ -#define __MARK_DIALOG_H__ -#ifdef I3 - - - -SwitcherMode mark_switcher_dialog ( char **input ); - -#endif -#endif diff --git a/include/simpleswitcher.h b/include/simpleswitcher.h index 3b33a6f7..fc9ec124 100644 --- a/include/simpleswitcher.h +++ b/include/simpleswitcher.h @@ -18,9 +18,6 @@ typedef enum { WINDOW_SWITCHER, RUN_DIALOG, SSH_DIALOG, -#ifdef I3 - MARK_DIALOG, -#endif #ifdef __QC_MODE__ PROFILE_DIALOG, #endif diff --git a/source/dmenu-dialog.c b/source/dmenu-dialog.c index fd466d98..8a5c8548 100644 --- a/source/dmenu-dialog.c +++ b/source/dmenu-dialog.c @@ -39,30 +39,15 @@ #include #include "simpleswitcher.h" -#include "mark-dialog.h" -#include -#include -#include -#include - -#ifdef TIMING -#include -#endif char *dmenu_prompt = "dmenu "; static char **get_dmenu ( ) { - -#ifdef TIMING - struct timespec start, stop; - clock_gettime( CLOCK_REALTIME, &start ); -#endif + char buffer[1024]; char **retv = NULL; int index = 0; - char buffer[1024]; - while ( fgets( buffer, 1024, stdin ) != NULL ) { retv = realloc( retv, ( index+2 )*sizeof( char* ) ); retv[index] = strdup( buffer ); @@ -74,18 +59,6 @@ static char **get_dmenu ( ) index++; } - - -#ifdef TIMING - clock_gettime( CLOCK_REALTIME, &stop ); - - if ( stop.tv_sec != start.tv_sec ) { - stop.tv_nsec += ( stop.tv_sec-start.tv_sec )*1e9; - } - - long diff = stop.tv_nsec-start.tv_nsec; - printf( "Time elapsed: %ld us\n", diff/1000 ); -#endif return retv; } @@ -105,14 +78,14 @@ static int token_match ( char **tokens, const char *input, SwitcherMode dmenu_switcher_dialog ( char **input ) { + int shift=0; + int selected_line = 0; SwitcherMode retv = MODE_EXIT; // act as a launcher char **list = get_dmenu( ); - - int shift=0; - int selected_line = 0; - int mretv = menu( list, input, dmenu_prompt,NULL, &shift,token_match, NULL, &selected_line ); + int mretv = menu( list, input, dmenu_prompt,NULL, &shift, + token_match, NULL, &selected_line ); if ( mretv == MENU_NEXT ) { retv = DMENU_DIALOG; diff --git a/source/mark-dialog.c b/source/mark-dialog.c deleted file mode 100644 index e87c27ff..00000000 --- a/source/mark-dialog.c +++ /dev/null @@ -1,296 +0,0 @@ -/** - * simpleswitcher - * - * MIT/X11 License - * Copyright 2013-2014 Qball Cow - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifdef I3 - -#define _GNU_SOURCE -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "simpleswitcher.h" -#include "mark-dialog.h" -#include -#include -#include -#include -#include - -#ifdef TIMING -#include -#endif - -static char * escape_name( const char *mark, ssize_t *length ) -{ - // Escape the mark. - // Max length is twice the old size + trailing \0. - char *escaped_mark = allocate ( sizeof( char )*( strlen( mark )*2+1 ) ); - ssize_t lm = strlen( mark ); - *length = 0; - - for ( ssize_t iter = 0; iter < lm; iter++ ) { - if ( mark[iter] == '\'' || mark[iter] == '\"' || mark[iter] == '\\' ) { - escaped_mark[( *length )++] = '\\'; - } - - escaped_mark[( *length )++] = mark[iter]; - escaped_mark[( *length )] = '\0'; - } - - return escaped_mark; -} - - -static void exec_mark( const char *mark ) -{ - int s, t, len; - struct sockaddr_un remote; - - if ( config.i3_mode == 0 ) { - fprintf( stderr, "Cannot use marks without i3 running\n" ); - return ; - } - - if ( strlen( i3_socket_path ) > UNIX_PATH_MAX ) { - fprintf( stderr, "Socket path is to long. %zd > %d\n", strlen( i3_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 ) ); - return; - } - - remote.sun_family = AF_UNIX; - strcpy( remote.sun_path, i3_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", i3_socket_path,strerror( errno ) ); - close( s ); - return ; - } - - -// Formulate command - ssize_t lem = 0; - char *escaped_mark = escape_name( mark, &lem ); - char command[lem+20]; - snprintf( command, lem+20, "[con_mark=\"%s\"] focus", escaped_mark ); - - // Prepare header. - i3_ipc_header_t head; - 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 message - send( s, command, strlen( command ),0 ); - - - // Receive result. - t = recv( s, &head, sizeof( head ),0 ); - - if ( t == sizeof( head ) ) { - t= recv( s, command, head.size, 0 ); - command[t] = '\0'; - printf( "%s\n", command ); - } - - close( s ); - - free( escaped_mark ); -} - -static char ** get_mark ( ) -{ - unsigned int retv_index = 0; - char **retv = NULL; - - if ( config.i3_mode == 0 ) { - fprintf( stderr, "Cannot use marks without i3 running\n" ); - return retv; - } - -#ifdef TIMING - struct timespec start, stop; - clock_gettime( CLOCK_REALTIME, &start ); -#endif - - i3_ipc_header_t head; - int s, t, len; - struct sockaddr_un remote; - - if ( strlen( i3_socket_path ) > UNIX_PATH_MAX ) { - fprintf( stderr, "Socket path is to long. %zd > %d\n", strlen( i3_socket_path ), UNIX_PATH_MAX ); - return retv; - } - - if ( ( s = socket( AF_UNIX, SOCK_STREAM, 0 ) ) == -1 ) { - fprintf( stderr, "Failed to open connection to I3: %s\n", strerror( errno ) ); - return retv; - } - - remote.sun_family = AF_UNIX; - strcpy( remote.sun_path, i3_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", i3_socket_path,strerror( errno ) ); - close( s ); - return retv; - } - - -// Formulate command - // Prepare header. - memcpy( head.magic, I3_IPC_MAGIC, 6 ); - head.size = 0; - head.type = I3_IPC_MESSAGE_TYPE_GET_MARKS; - // Send header. - send( s, &head, sizeof( head ),0 ); - // Receive header. - t = recv( s, &head, sizeof( head ),0 ); - - if ( t == sizeof( head ) ) { - char *result = allocate ( sizeof( char )*( head.size+1 ) ); - ssize_t index = 0; - t = 0; - - // Grab results. - while ( index < ( ssize_t )head.size ) { - t= recv( s, &result[index], ( head.size-t ), 0 ); - - if ( t < 0 ) break; - - result[index+t] = '\0'; - index+=t; - } - - for ( int iter_start = 1; iter_start < index-1 ; iter_start++ ) { - // Skip , and opening " - if ( result[iter_start] == '"' || result[iter_start] == ',' ) continue; - - int iter_end = iter_start; - - // Find closing tag.. make sure to ignore escaped chars. - // Copy the un-escaped string into the first part. - int rindex = 0; - - do { - result[rindex++] = result[iter_end]; - iter_end++; - - if ( result[iter_end] == '\\' ) iter_end+=1; - } while ( result[iter_end] != '"' ); - - result[rindex] = '\0'; - - // Add element to list. - retv = realloc( retv, ( retv_index+2 )*sizeof( char* ) ); - retv[retv_index] = strndup( result,rindex ); - retv[retv_index+1] = NULL; - retv_index++; - - iter_start = iter_end; - } - - free( result ); - } - - close( s ); - -#ifdef TIMING - clock_gettime( CLOCK_REALTIME, &stop ); - - if ( stop.tv_sec != start.tv_sec ) { - stop.tv_nsec += ( stop.tv_sec-start.tv_sec )*1e9; - } - - long diff = stop.tv_nsec-start.tv_nsec; - printf( "Time elapsed: %ld us\n", diff/1000 ); -#endif - return retv; -} - -static int token_match ( char **tokens, const char *input, - __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 ); - } - - return match; -} - -SwitcherMode mark_switcher_dialog ( char **input ) -{ - SwitcherMode retv = MODE_EXIT; - // act as a launcher - char **cmd_list = get_mark( ); - - if ( cmd_list == NULL ) { - cmd_list = allocate( 2*sizeof( char * ) ); - cmd_list[0] = strdup( "No i3 marks found" ); - cmd_list[1] = NULL; - } - - int shift=0; - int selected_line = 0; - int mretv = menu( cmd_list, input, "mark:", NULL, &shift,token_match,NULL, &selected_line ); - - if ( mretv == MENU_NEXT ) { - retv = NEXT_DIALOG; - } else if ( mretv == MENU_OK && cmd_list[selected_line] != NULL ) { - exec_mark( cmd_list[selected_line] ); - } else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) { - exec_mark( *input ); - } - - for ( int i=0; cmd_list != NULL && cmd_list[i] != NULL; i++ ) { - free( cmd_list[i] ); - } - - if ( cmd_list ) free( cmd_list ); - - - return retv; -} - -#endif diff --git a/source/simpleswitcher.c b/source/simpleswitcher.c index c57f8c34..b0d2c0aa 100644 --- a/source/simpleswitcher.c +++ b/source/simpleswitcher.c @@ -64,7 +64,6 @@ #include "simpleswitcher.h" #include "run-dialog.h" #include "ssh-dialog.h" -#include "mark-dialog.h" #include "profile-dialog.h" #include "dmenu-dialog.h" @@ -660,11 +659,6 @@ KeySym rundialog_keysym; unsigned int sshdialog_modmask; KeySym sshdialog_keysym; -#ifdef I3 -unsigned int markdialog_modmask; -KeySym markdialog_keysym; -#endif - Window main_window = None; GC gc = NULL; @@ -1245,13 +1239,6 @@ void run_switcher( int fmode, SwitcherMode mode ) } else if ( mode == SSH_DIALOG ) { retv = ssh_switcher_dialog( &input ); } - -#ifdef I3 - else if ( mode == MARK_DIALOG ) { - retv = mark_switcher_dialog ( &input ); - } - -#endif #ifdef __QC_MODE__ else if ( mode == PROFILE_DIALOG ) { retv = profile_switcher_dialog ( &input ); @@ -1298,14 +1285,6 @@ void handle_keypress( XEvent *ev ) run_switcher( FORK , SSH_DIALOG ); } -#ifdef I3 - - if ( ( markdialog_modmask == AnyModifier || ev->xkey.state & markdialog_modmask ) && - key == markdialog_keysym ) { - run_switcher( FORK , MARK_DIALOG ); - } - -#endif } // convert a Mod+key arg to mod mask and keysym @@ -1498,10 +1477,6 @@ int main( int argc, char *argv[] ) run_switcher( NOFORK, RUN_DIALOG ); } else if ( find_arg( argc, argv, "-snow" ) >= 0 ) { run_switcher( NOFORK, SSH_DIALOG ); -#ifdef I3 - } else if ( find_arg( argc, argv, "-mnow" ) >= 0 ) { - run_switcher( NOFORK, MARK_DIALOG ); -#endif } else if ( find_arg( argc, argv, "-dmenu" ) >= 0 ) { find_arg_str( argc, argv, "-p", &dmenu_prompt ); run_switcher( NOFORK, DMENU_DIALOG ); @@ -1519,13 +1494,6 @@ int main( int argc, char *argv[] ) find_arg_str( argc, argv, "-skey",&( config.ssh_key ) ); parse_key( config.ssh_key, &sshdialog_modmask, &sshdialog_keysym ); grab_key( sshdialog_modmask, sshdialog_keysym ); - // bind key combos -#ifdef I3 - find_arg_str( argc, argv, "-mkey",&( config.mark_key ) ); - parse_key( config.mark_key, &markdialog_modmask, &markdialog_keysym ); - grab_key( markdialog_modmask, markdialog_keysym ); -#endif - XEvent ev;