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:
parent
f995944734
commit
7eac636fc8
@ -61,6 +61,7 @@
|
||||
#include "command/cmd_defs.h"
|
||||
#include "plugins/plugins.h"
|
||||
#include "event/client_events.h"
|
||||
#include "ui/inputwin.h"
|
||||
#include "ui/ui.h"
|
||||
#include "ui/window_list.h"
|
||||
#include "xmpp/resource.h"
|
||||
@ -91,7 +92,7 @@ static gboolean _main_update(gpointer data);
|
||||
|
||||
pthread_mutex_t lock;
|
||||
static gboolean force_quit = FALSE;
|
||||
static GMainLoop* main_loop = NULL;
|
||||
GMainLoop* mainloop = NULL;
|
||||
|
||||
void
|
||||
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();
|
||||
|
||||
main_loop = g_main_loop_new(NULL, TRUE);
|
||||
mainloop = g_main_loop_new(NULL, TRUE);
|
||||
g_timeout_add(1000/60, _main_update, NULL);
|
||||
g_main_loop_run(main_loop);
|
||||
inp_add_watch();
|
||||
g_main_loop_run(mainloop);
|
||||
}
|
||||
|
||||
void
|
||||
@ -123,15 +125,6 @@ _main_update(gpointer data)
|
||||
log_stderr_handler();
|
||||
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
|
||||
otr_poll();
|
||||
#endif
|
||||
@ -144,9 +137,6 @@ _main_update(gpointer data)
|
||||
tray_update();
|
||||
#endif
|
||||
|
||||
if (!cont)
|
||||
g_main_loop_quit(main_loop);
|
||||
|
||||
// Always repeat
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -44,5 +44,6 @@ void prof_run(char* log_level, char* account_name, char* config_file, char* log_
|
||||
void prof_set_quit(void);
|
||||
|
||||
extern pthread_mutex_t lock;
|
||||
extern GMainLoop* mainloop;
|
||||
|
||||
#endif
|
||||
|
@ -171,6 +171,44 @@ create_input_window(void)
|
||||
_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*
|
||||
inp_readline(void)
|
||||
{
|
||||
|
@ -46,5 +46,6 @@ void inp_win_resize(void);
|
||||
void inp_put_back(void);
|
||||
char* inp_get_password(void);
|
||||
char* inp_get_line(void);
|
||||
void inp_add_watch(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user