mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-03 04:23:42 -05:00
also accept . in ssh hostname
This commit is contained in:
parent
8b6b494830
commit
b0ee6ab8dd
4 changed files with 82 additions and 60 deletions
|
@ -49,7 +49,7 @@ Settings config = {
|
||||||
.run_key = "mod1+F2",
|
.run_key = "mod1+F2",
|
||||||
.ssh_key = "mod1+F3",
|
.ssh_key = "mod1+F3",
|
||||||
#ifdef I3
|
#ifdef I3
|
||||||
.mark_key = "mod1+F5",
|
.mark_key = "mod1+F5",
|
||||||
#endif
|
#endif
|
||||||
.location = CENTER,
|
.location = CENTER,
|
||||||
.wmode = VERTICAL,
|
.wmode = VERTICAL,
|
||||||
|
|
|
@ -51,32 +51,36 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static char * escape_name(const char *mark, ssize_t *length)
|
static char * escape_name( const char *mark, ssize_t *length )
|
||||||
{
|
{
|
||||||
// Escape the mark.
|
// Escape the mark.
|
||||||
// Max length is twice the old size + trailing \0.
|
// Max length is twice the old size + trailing \0.
|
||||||
char *escaped_mark = malloc(sizeof(char)*(strlen(mark)*2+1));
|
char *escaped_mark = malloc( sizeof( char )*( strlen( mark )*2+1 ) );
|
||||||
ssize_t lm = strlen(mark);
|
ssize_t lm = strlen( mark );
|
||||||
*length = 0;
|
*length = 0;
|
||||||
for(ssize_t iter = 0; iter < lm; iter++) {
|
|
||||||
if(mark[iter] == '\'' || mark[iter] == '\"' || mark[iter] == '\\') {
|
for ( ssize_t iter = 0; iter < lm; iter++ ) {
|
||||||
escaped_mark[(*length)++] = '\\';
|
if ( mark[iter] == '\'' || mark[iter] == '\"' || mark[iter] == '\\' ) {
|
||||||
}
|
escaped_mark[( *length )++] = '\\';
|
||||||
escaped_mark[(*length)++] = mark[iter];
|
}
|
||||||
escaped_mark[(*length)] = '\0';
|
|
||||||
}
|
escaped_mark[( *length )++] = mark[iter];
|
||||||
return escaped_mark;
|
escaped_mark[( *length )] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return escaped_mark;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void exec_mark(const char *mark)
|
static void exec_mark( const char *mark )
|
||||||
{
|
{
|
||||||
int s, t, len;
|
int s, t, len;
|
||||||
struct sockaddr_un remote;
|
struct sockaddr_un remote;
|
||||||
if(config.i3_mode == 0) {
|
|
||||||
fprintf(stderr, "Cannot use marks without i3 running\n");
|
if ( config.i3_mode == 0 ) {
|
||||||
return ;
|
fprintf( stderr, "Cannot use marks without i3 running\n" );
|
||||||
}
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
if ( strlen( i3_socket_path ) > UNIX_PATH_MAX ) {
|
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 );
|
fprintf( stderr, "Socket path is to long. %zd > %d\n", strlen( i3_socket_path ), UNIX_PATH_MAX );
|
||||||
|
@ -100,10 +104,10 @@ static void exec_mark(const char *mark)
|
||||||
|
|
||||||
|
|
||||||
// Formulate command
|
// Formulate command
|
||||||
ssize_t lem = 0;
|
ssize_t lem = 0;
|
||||||
char *escaped_mark = escape_name(mark, &lem);
|
char *escaped_mark = escape_name( mark, &lem );
|
||||||
char command[lem+20];
|
char command[lem+20];
|
||||||
snprintf( command, lem+20, "[con_mark=\"%s\"] focus", escaped_mark);
|
snprintf( command, lem+20, "[con_mark=\"%s\"] focus", escaped_mark );
|
||||||
|
|
||||||
// Prepare header.
|
// Prepare header.
|
||||||
i3_ipc_header_t head;
|
i3_ipc_header_t head;
|
||||||
|
@ -127,17 +131,19 @@ static void exec_mark(const char *mark)
|
||||||
|
|
||||||
close( s );
|
close( s );
|
||||||
|
|
||||||
free(escaped_mark);
|
free( escaped_mark );
|
||||||
}
|
}
|
||||||
|
|
||||||
static char ** get_mark ( )
|
static char ** get_mark ( )
|
||||||
{
|
{
|
||||||
unsigned int retv_index = 0;
|
unsigned int retv_index = 0;
|
||||||
char **retv = NULL;
|
char **retv = NULL;
|
||||||
if(config.i3_mode == 0) {
|
|
||||||
fprintf(stderr, "Cannot use marks without i3 running\n");
|
if ( config.i3_mode == 0 ) {
|
||||||
return retv;
|
fprintf( stderr, "Cannot use marks without i3 running\n" );
|
||||||
}
|
return retv;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef TIMING
|
#ifdef TIMING
|
||||||
struct timespec start, stop;
|
struct timespec start, stop;
|
||||||
clock_gettime( CLOCK_REALTIME, &start );
|
clock_gettime( CLOCK_REALTIME, &start );
|
||||||
|
@ -171,7 +177,7 @@ static char ** get_mark ( )
|
||||||
// Formulate command
|
// Formulate command
|
||||||
// Prepare header.
|
// Prepare header.
|
||||||
memcpy( head.magic, I3_IPC_MAGIC, 6 );
|
memcpy( head.magic, I3_IPC_MAGIC, 6 );
|
||||||
head.size = 0;
|
head.size = 0;
|
||||||
head.type = I3_IPC_MESSAGE_TYPE_GET_MARKS;
|
head.type = I3_IPC_MESSAGE_TYPE_GET_MARKS;
|
||||||
// Send header.
|
// Send header.
|
||||||
send( s, &head, sizeof( head ),0 );
|
send( s, &head, sizeof( head ),0 );
|
||||||
|
@ -179,40 +185,48 @@ static char ** get_mark ( )
|
||||||
t = recv( s, &head, sizeof( head ),0 );
|
t = recv( s, &head, sizeof( head ),0 );
|
||||||
|
|
||||||
if ( t == sizeof( head ) ) {
|
if ( t == sizeof( head ) ) {
|
||||||
char *result = malloc(sizeof(char)*(head.size+1));
|
char *result = malloc( sizeof( char )*( head.size+1 ) );
|
||||||
ssize_t index = 0;
|
ssize_t index = 0;
|
||||||
// Grab results.
|
|
||||||
while(index < 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.
|
// Grab results.
|
||||||
// Copy the un-escaped string into the first part.
|
while ( index < head.size ) {
|
||||||
int rindex = 0;
|
t= recv( s, &result[index], ( head.size-t ), 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.
|
if ( t < 0 ) break;
|
||||||
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;
|
result[index+t] = '\0';
|
||||||
}
|
index+=t;
|
||||||
|
}
|
||||||
|
|
||||||
free(result);
|
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 );
|
close( s );
|
||||||
|
|
|
@ -1185,11 +1185,14 @@ void run_switcher( int fmode, SwitcherMode mode )
|
||||||
} else if ( mode == SSH_DIALOG ) {
|
} else if ( mode == SSH_DIALOG ) {
|
||||||
retv = ssh_switcher_dialog( &input );
|
retv = ssh_switcher_dialog( &input );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef I3
|
#ifdef I3
|
||||||
else if ( mode == MARK_DIALOG ) {
|
else if ( mode == MARK_DIALOG ) {
|
||||||
retv = mark_switcher_dialog ( &input );
|
retv = mark_switcher_dialog ( &input );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( retv == NEXT_DIALOG ) {
|
if ( retv == NEXT_DIALOG ) {
|
||||||
mode = ( mode+1 )%NUM_DIALOGS;
|
mode = ( mode+1 )%NUM_DIALOGS;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1225,11 +1228,14 @@ void handle_keypress( XEvent *ev )
|
||||||
key == sshdialog_keysym ) {
|
key == sshdialog_keysym ) {
|
||||||
run_switcher( FORK , SSH_DIALOG );
|
run_switcher( FORK , SSH_DIALOG );
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef I3
|
#ifdef I3
|
||||||
|
|
||||||
if ( ( markdialog_modmask == AnyModifier || ev->xkey.state & markdialog_modmask ) &&
|
if ( ( markdialog_modmask == AnyModifier || ev->xkey.state & markdialog_modmask ) &&
|
||||||
key == markdialog_keysym ) {
|
key == markdialog_keysym ) {
|
||||||
run_switcher( FORK , MARK_DIALOG );
|
run_switcher( FORK , MARK_DIALOG );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -176,7 +176,9 @@ static char ** get_ssh ( )
|
||||||
|
|
||||||
for ( start=4; isspace( buffer[start] ); start++ );
|
for ( start=4; isspace( buffer[start] ); start++ );
|
||||||
|
|
||||||
for ( stop=start; isalnum( buffer[stop] ) || buffer[stop] == '_' ; stop++ );
|
for ( stop=start; isalnum( buffer[stop] ) ||
|
||||||
|
buffer[stop] == '_' ||
|
||||||
|
buffer[stop] == '.' ; stop++ );
|
||||||
|
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue