openbsd98324 |
11-05-2023 05:54 AM |
Quote:
Originally Posted by Lindgren
(Post 6462767)
Sounds interesting for sure, a little curious about that unixsocket/loop, do you have an example of that?
Nice! Have been looking for something described like that, will try along with bspwm.
|
Code:
char *strninput( char *myinitstring )
{
int strninput_gameover = 0;
char strmsg[PATH_MAX];
char charo[PATH_MAX];
strncpy( strmsg, myinitstring , PATH_MAX );
int ch ; int foo ;
int fooj;
while ( strninput_gameover == 0 )
{
getmaxyx( stdscr, rows, cols);
attroff( A_REVERSE );
for ( fooj = 0 ; fooj <= cols-1; fooj++)
{
mvaddch( rows-1, fooj , ' ' );
}
mvprintw( rows-1, 0, ":> %s" , strrlf( strmsg ) );
attron( A_REVERSE );
printw( " " );
attroff( A_REVERSE );
attroff( A_REVERSE );
attroff( A_BOLD );
refresh() ;
curs_set( 0 );
ch = getch();
if ( ch == 8 )
strncpy( strmsg, strcut( strmsg, 1 , strlen( strmsg ) -1 ) , PATH_MAX );
else if ( ch == 27 )
{
strncpy( strmsg, "" , PATH_MAX );
strninput_gameover = 1;
}
else if ( ch == 274 )
{
strncpy( strmsg, "" , PATH_MAX );
strninput_gameover = 1;
}
else if ( ch == 263 )
strncpy( strmsg, strcut( strmsg, 1 , strlen( strmsg ) -1 ) , PATH_MAX );
else if ( ch == 4 )
strncpy( strmsg, "" , PATH_MAX );
else if ( ch == 4 )
{
strncpy( strmsg, "" , PATH_MAX );
}
else if ( ch == 27 )
{
strncpy( strmsg, "" , PATH_MAX );
}
else if (
(( ch >= 'a' ) && ( ch <= 'z' ) )
|| (( ch >= 'A' ) && ( ch <= 'Z' ) )
|| (( ch >= '1' ) && ( ch <= '9' ) )
|| (( ch == '0' ) )
|| (( ch == '~' ) )
|| (( ch == '!' ) )
|| (( ch == '&' ) )
|| (( ch == '=' ) )
|| (( ch == ':' ) )
|| (( ch == ';' ) )
|| (( ch == '<' ) )
|| (( ch == '>' ) )
|| (( ch == ' ' ) )
|| (( ch == '|' ) )
|| (( ch == '#' ) )
|| (( ch == '?' ) )
|| (( ch == '+' ) )
|| (( ch == '/' ) )
|| (( ch == '\\' ) )
|| (( ch == '.' ) )
|| (( ch == '$' ) )
|| (( ch == '%' ) )
|| (( ch == '-' ) )
|| (( ch == ',' ) )
|| (( ch == '{' ) )
|| (( ch == '}' ) )
|| (( ch == '(' ) )
|| (( ch == ')' ) )
|| (( ch == ']' ) )
|| (( ch == '[' ) )
|| (( ch == '*' ) )
|| (( ch == '"' ) )
|| (( ch == '@' ) )
|| (( ch == '-' ) )
|| (( ch == '_' ) )
|| (( ch == '^' ) )
|| (( ch == '\'' ) )
)
{
foo = snprintf( charo, PATH_MAX , "%s%c", strmsg, ch );
strncpy( strmsg, charo , PATH_MAX );
}
else if ( ch == 10 )
{
strninput_gameover = 1;
}
}
char ptr[PATH_MAX];
strncpy( ptr, strmsg, PATH_MAX );
size_t siz = sizeof ptr ;
char *r = malloc( sizeof ptr );
return r ? memcpy(r, ptr, siz ) : NULL;
}
///////////////////////////////
///////////////////////////////
///////////////////////////////
char *strtimestamp()
{
long t;
struct tm *ltime;
time(&t);
ltime=localtime(&t);
char charo[50]; int fooi ;
fooi = snprintf( charo, 50 , "%04d%02d%02d%02d%02d%02d",
1900 + ltime->tm_year, ltime->tm_mon +1 , ltime->tm_mday,
ltime->tm_hour, ltime->tm_min, ltime->tm_sec
);
size_t siz = sizeof charo ;
char *r = malloc( sizeof charo );
return r ? memcpy(r, charo, siz ) : NULL;
}
////////////////////////////////
////////////////////////////////
////////////////////////////////
void mvcenter( int myposypass, char *mytext )
{
mvprintw( myposypass, cols/2 - strlen( mytext )/2 , "%s", mytext );
}
void gfxrectangle( int y1, int x1, int y2, int x2 )
{
int foo, fooy , foox ;
foo = x1;
for( fooy = y1 ; fooy <= y2 ; fooy++)
for( foox = x1 ; foox <= x2 ; foox++)
mvaddch( fooy , foox , ' ' );
}
void gfxframe( int y1, int x1, int y2, int x2 )
{
int foo, fooy , foox ;
foo = x1;
for( fooy = y1 ; fooy <= y2 ; fooy++)
mvaddch( fooy , foo , ACS_VLINE );
foo = x2;
for( fooy = y1 ; fooy <= y2 ; fooy++)
mvaddch( fooy , foo , ACS_VLINE );
foo = y1;
for( foox = x1 ; foox <= x2 ; foox++)
mvaddch( foo , foox , ACS_HLINE );
foo = y2;
for( foox = x1 ; foox <= x2 ; foox++)
mvaddch( foo , foox , ACS_HLINE );
mvaddch( y1 , x1 , ACS_ULCORNER );
mvaddch( y1 , x2 , ACS_URCORNER );
mvaddch( y2 , x1 , ACS_LLCORNER );
mvaddch( y2 , x2 , ACS_LRCORNER );
}
void ncurses_runcmd( char *thecmd )
{
char rncmdi[PATH_MAX];
def_prog_mode();
endwin();
strncpy( rncmdi , " " , PATH_MAX );
strncat( rncmdi , thecmd , PATH_MAX - strlen( rncmdi ) -1 );
strncat( rncmdi , " " , PATH_MAX - strlen( rncmdi ) -1 );
system( rncmdi );
reset_prog_mode();
}
void tcxdotool_screenshot( int tcxmode )
{
char cmdi[PATH_MAX];
char thefilename[PATH_MAX];
char lastfile[PATH_MAX];
def_prog_mode();
endwin();
printf( " Entering sleep X... before shot!\n" );
system( " sleep 1 " );
strncpy( lastfile, "" , PATH_MAX );
strncat( lastfile , strtimestamp() , PATH_MAX - strlen( lastfile ) -1 );
strncat( lastfile , "-" , PATH_MAX - strlen( lastfile ) -1 );
//strncat( lastfile , "screenshot.png" , PATH_MAX - strlen( lastfile ) -1 );
strncat( lastfile , filename_description , PATH_MAX - strlen( lastfile ) -1 );
strncat( lastfile , ".png" , PATH_MAX - strlen( lastfile ) -1 );
if ( tcxmode == 1 ) strncpy( cmdi , " scrot " , PATH_MAX );
else if ( tcxmode == 2 ) strncpy( cmdi , " scrot -s " , PATH_MAX );
strncat( cmdi , " \"" , PATH_MAX - strlen( cmdi ) -1 );
strncat( cmdi , lastfile , PATH_MAX - strlen( cmdi ) -1 );
strncat( cmdi , "\" " , PATH_MAX - strlen( cmdi ) -1 );
strncat( cmdi , " " , PATH_MAX - strlen( cmdi ) -1 );
printf( " Let it shot!\n" );
printf( "cmd: %s\n", cmdi );
system( cmdi );
reset_prog_mode();
}
void menu_xdotool()
{
char charo[PATH_MAX];
.....
//// area removed
{
erase();
mvprintw( 0, 0, "mode arrow (hjkl, browser mode): %d" , mode_arrow_keys );
color_set( 13, NULL ); attroff( A_REVERSE );
gfxrectangle( rows*25/100, cols*25/100 , rows*75/100, cols*75/100 );
gfxframe( rows*25/100, cols*25/100 , rows*75/100, cols*75/100 );
color_set( 17, NULL ); attron( A_REVERSE );
mvcenter( rows*25/100, "| Menu Xdotool |" );
color_set( 13, NULL ); attroff( A_REVERSE );
mvprintw( rows*25/100 +2, cols*25/100+2, "h,j,k,l: xdotool keys ..." );
mvprintw( rows*25/100 +3, cols*25/100+2, "[0]: Screenshot (scrot!)" );
mvprintw( rows*25/100 +4, cols*25/100+2, "[9]: Screenshot (scrot selection !)" );
mvprintw( rows*25/100 +5, cols*25/100+2, "[1]: Screenshot (set filename)" );
mvprintw( rows*25/100 +5, cols*25/100+2, "[M]: Max (current window)" );
mvprintw( rows*25/100 +6, cols*25/100+2, " [%s]", filename_description );
color_set( 5, NULL ); attron( A_REVERSE );
mvcenter( rows*75/100 -1, "[ Esc: Cancel ]" );
mvprintw( rows-1, 0, "|%d|", ch );
ch = getch();
if ( mode_arrow_keys == 1 )
{
if ( ch == 'k' ) ncurses_runcmd( " xdotool key Up " );
else if ( ch == 'j' ) ncurses_runcmd( " xdotool key Down " );
else if ( ch == 'h' ) ncurses_runcmd( " xdotool key Left " );
else if ( ch == 'l' ) ncurses_runcmd( " xdotool key Right " );
else if ( ch == 'n' ) ncurses_runcmd( " xdotool key Next " );
else if ( ch == 10 ) ncurses_runcmd( " xdotool key Return " );
else if ( ch == 9 ) ncurses_runcmd( " xdotool key Tab " );
if ( ch == 'k' ) ch = 0;
else if ( ch == 'j' ) ch = 0;
else if ( ch == 'h' ) ch = 0;
else if ( ch == 'l' ) ch = 0;
else if ( ch == 'n' ) ch = 0;
else if ( ch == 10 ) ch = 0;
else if ( ch == 9 ) ch = 0;
}
if ( ch == 'j' )
ncurses_runcmd( " xdotool key j " );
else if ( ch == 27 )
ncurses_runcmd( " xdotool key Escape " );
else if ( ch == 10 ) ncurses_runcmd( " xdotool key Return " );
else if ( ch == 9 ) ncurses_runcmd( " xdotool key Tab " );
// F-x keys
else if ( ch == 265 ) ncurses_runcmd( " xdotool key F1 " );
else if ( ch == 266 ) ncurses_runcmd( " xdotool key F2 " );
else if ( ch == 267 ) ncurses_runcmd( " xdotool key F3 " );
else if ( ch == 268 ) ncurses_runcmd( " xdotool key F4 " );
else if ( ch == 269 ) ncurses_runcmd( " xdotool key F5 " );
else if ( ch == 270 ) ncurses_runcmd( " xdotool key F6 " );
else if ( ch == 271 ) ncurses_runcmd( " xdotool key F7 " );
else if ( ch == 272 ) ncurses_runcmd( " xdotool key F8 " );
else if ( ch == 273 ) ncurses_runcmd( " xdotool key F9 " );
else if ( ch == 274 ) ncurses_runcmd( " xdotool key F10 " );
else if ( ch == 275 ) ncurses_runcmd( " xdotool key F11 " );
else if ( ch == 276 ) ncurses_runcmd( " xdotool key F12 " );
else if ( ch == '#' )
{
if ( mode_arrow_keys == 0 )
mode_arrow_keys = 1;
else
mode_arrow_keys = 0;
}
else if ( ch == 'M' )
ncurses_runcmd( " wmctrl -r :ACTIVE: -b toggle,maximized_vert,maximized_horz ");
else if ( ch == KEY_UP ) ncurses_runcmd( " xdotool key Up " );
else if ( ch == KEY_DOWN ) ncurses_runcmd( " xdotool key Down " );
else if ( ch == KEY_LEFT ) ncurses_runcmd( " xdotool key Left " );
else if ( ch == KEY_RIGHT ) ncurses_runcmd( " xdotool key Right " );
else if ( ch == 'u' ) ncurses_runcmd( " xdotool key Prior " );
else if ( ch == 'd' ) ncurses_runcmd( " xdotool key Next " );
else if ( ch == 'G' ) ncurses_runcmd( " xdotool key G " );
else if ( ch == 'g' ) ncurses_runcmd( " xdotool key g " );
else if ( ch == 'm' ) ncurses_runcmd( " xdotool key m " );
else if ( ch == 'j' ) ncurses_runcmd( " xdotool key j " );
else if ( ch == 'k' ) ncurses_runcmd( " xdotool key k " );
else if ( ch == 'h' ) ncurses_runcmd( " xdotool key h " );
else if ( ch == 'l' ) ncurses_runcmd( " xdotool key l " );
else if ( ch == 'B' ) ncurses_runcmd( " xdotool key B " );
else if ( ch == 'b' ) ncurses_runcmd( " xdotool key b " );
else if ( ch == 'z' ) ncurses_runcmd( " xdotool key z " );
else if ( ch == '+' ) ncurses_runcmd( " xdotool key plus " );
else if ( ch == '-' ) ncurses_runcmd( " xdotool key minus " );
else if ( ch == 'Z' ) ncurses_runcmd( " xdotool key Z " );
else if ( ch == 'z' ) ncurses_runcmd( " xdotool key z " );
else if ( ch == 'f' ) ncurses_runcmd( " xdotool key f " );
else if ( ch == 'F' ) ncurses_runcmd( " xdotool key F " );
else if ( ch == 'q' ) ncurses_runcmd( " xdotool key q " );
else if ( ch == 'Q' ) ncurses_runcmd( " xdotool key Q " );
else if ( ch == 32 ) ncurses_runcmd( " xdotool key space " );
else if ( ch == '0' ) tcxdotool_screenshot( 1 );
else if ( ch == '1' ) strncpy( filename_description, strninput( "" ) , PATH_MAX );
else if ( ch == '<' )
ncurses_runcmd( " xdotool key less " );
else if ( ch == '>' )
ncurses_runcmd( " xdotool key greater " );
else if ( ch == '#' )
ncurses_runcmd( " xdotool key numbersign " );
else if ( ch == KEY_RIGHT ) ncurses_runcmd( " xdotool key Right " );
else if ( ch == KEY_LEFT ) ncurses_runcmd( " xdotool key Left " );
else if ( ch != 0 )
{
snprintf( charo , sizeof( charo ), " xdotool key %c " , ch );
///printf( "Command to force umount: %s\n", charo );
system( charo );
}
/*
else
switch( ch )
{
case '+':
ncurses_runcmd( " xdotool key KP_Add " );
break;
case '-':
ncurses_runcmd( " xdotool key KP_Subtract " );
break;
case 4: //ctrl+d
ncurses_runcmd( " xdotool key Page_Down " );
break;
case 21: //ctrl+u
ncurses_runcmd( " xdotool key Page_Up " );
break;
case 32:
ncurses_runcmd( " xdotool key space " );
break;
case 127:
ncurses_runcmd( " xdotool key BackSpace " );
break;
}
*/
}
}
int main()
{
strncpy(filename_description, "screenshot", PATH_MAX );
initscr();
curs_set( 0 );
noecho();
keypad( stdscr, TRUE ); // for Function keys
start_color();
init_pair(0, COLOR_WHITE, COLOR_BLACK);
init_pair(1, COLOR_RED, COLOR_BLACK);
init_pair(2, COLOR_GREEN, COLOR_BLACK);
init_pair(3, COLOR_YELLOW, COLOR_BLACK);
init_pair(4, COLOR_BLUE, COLOR_BLACK);
init_pair(5, COLOR_MAGENTA, COLOR_BLACK);
init_pair(6, COLOR_CYAN, COLOR_BLACK);
init_pair(7, COLOR_BLUE, COLOR_WHITE);
init_pair(8, COLOR_WHITE, COLOR_RED);
init_pair(9, COLOR_BLACK, COLOR_GREEN);
init_pair(10, COLOR_BLUE, COLOR_YELLOW );
init_pair(11, COLOR_WHITE, COLOR_BLUE);
init_pair(12, COLOR_YELLOW, COLOR_BLUE);
init_pair(13, COLOR_BLACK, COLOR_CYAN);
init_pair(14, COLOR_BLUE, COLOR_GREEN);
init_pair(15, COLOR_BLUE, COLOR_CYAN );
init_pair(16, COLOR_CYAN, COLOR_WHITE );
init_pair(17, COLOR_CYAN, COLOR_YELLOW );
init_pair(18, COLOR_CYAN, COLOR_BLUE);
init_pair( 19, COLOR_MAGENTA , COLOR_BLUE);
init_pair( 20 , COLOR_RED , COLOR_BLUE);
init_pair( 21 , COLOR_BLUE , COLOR_YELLOW);
init_pair( 22, COLOR_YELLOW, COLOR_CYAN);
init_pair( 23, COLOR_WHITE, COLOR_BLUE);
init_pair( 24, COLOR_GREEN, COLOR_BLUE);
getmaxyx( stdscr, rows , cols);
menu_xdotool();
endwin();
return 0;
}
|