1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Implement keyboard input using GIOChannel

This commit is contained in:
Rodrigo Arias 2022-01-09 21:53:52 +01:00 committed by John Hernandez
parent f995944734
commit 7eac636fc8
No known key found for this signature in database
GPG Key ID: 00B2D64859378A94
4 changed files with 45 additions and 15 deletions

View File

@ -61,6 +61,7 @@
#include "command/cmd_defs.h" #include "command/cmd_defs.h"
#include "plugins/plugins.h" #include "plugins/plugins.h"
#include "event/client_events.h" #include "event/client_events.h"
#include "ui/inputwin.h"
#include "ui/ui.h" #include "ui/ui.h"
#include "ui/window_list.h" #include "ui/window_list.h"
#include "xmpp/resource.h" #include "xmpp/resource.h"
@ -91,7 +92,7 @@ static gboolean _main_update(gpointer data);
pthread_mutex_t lock; pthread_mutex_t lock;
static gboolean force_quit = FALSE; static gboolean force_quit = FALSE;
static GMainLoop* main_loop = NULL; GMainLoop* mainloop = NULL;
void void
prof_run(char* log_level, char* account_name, char* config_file, char* log_file, char* theme_name) prof_run(char* log_level, char* account_name, char* config_file, char* log_file, char* theme_name)
@ -106,9 +107,10 @@ prof_run(char* log_level, char* account_name, char* config_file, char* log_file,
session_init_activity(); session_init_activity();
main_loop = g_main_loop_new(NULL, TRUE); mainloop = g_main_loop_new(NULL, TRUE);
g_timeout_add(1000/60, _main_update, NULL); g_timeout_add(1000/60, _main_update, NULL);
g_main_loop_run(main_loop); inp_add_watch();
g_main_loop_run(mainloop);
} }
void void
@ -123,15 +125,6 @@ _main_update(gpointer data)
log_stderr_handler(); log_stderr_handler();
session_check_autoaway(); session_check_autoaway();
gboolean cont = TRUE;
char *line = inp_readline();
if (line) {
ProfWin* window = wins_get_current();
cont = cmd_process_input(window, line);
free(line);
line = NULL;
}
#ifdef HAVE_LIBOTR #ifdef HAVE_LIBOTR
otr_poll(); otr_poll();
#endif #endif
@ -144,9 +137,6 @@ _main_update(gpointer data)
tray_update(); tray_update();
#endif #endif
if (!cont)
g_main_loop_quit(main_loop);
// Always repeat // Always repeat
return TRUE; return TRUE;
} }

View File

@ -44,5 +44,6 @@ void prof_run(char* log_level, char* account_name, char* config_file, char* log_
void prof_set_quit(void); void prof_set_quit(void);
extern pthread_mutex_t lock; extern pthread_mutex_t lock;
extern GMainLoop* mainloop;
#endif #endif

View File

@ -171,6 +171,44 @@ create_input_window(void)
_inp_win_update_virtual(); _inp_win_update_virtual();
} }
static gboolean
_inp_callback(GIOChannel *source, GIOCondition condition, gpointer data)
{
rl_callback_read_char();
ui_reset_idle_time();
if (!get_password) {
// Update the input buffer on screen
_inp_write(rl_line_buffer, rl_point);
}
// TODO set idle or activity with a timeout
//chat_state_idle();
//chat_state_activity();
if (inp_line) {
ProfWin* window = wins_get_current();
if (!cmd_process_input(window, inp_line))
g_main_loop_quit(mainloop);
free(inp_line);
inp_line = NULL;
}
return TRUE;
}
void
inp_add_watch(void)
{
GIOChannel* channel = g_io_channel_unix_new(fileno(rl_instream));
if (g_io_channel_set_encoding(channel, NULL, NULL) != G_IO_STATUS_NORMAL) {
log_error("cannot set NULL encoding");
}
g_io_add_watch(channel, G_IO_IN, _inp_callback, NULL);
}
char* char*
inp_readline(void) inp_readline(void)
{ {

View File

@ -46,5 +46,6 @@ void inp_win_resize(void);
void inp_put_back(void); void inp_put_back(void);
char* inp_get_password(void); char* inp_get_password(void);
char* inp_get_line(void); char* inp_get_line(void);
void inp_add_watch(void);
#endif #endif