mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 17:33:25 +01:00
Merge branch 'keybinds'
configurable keybinds finished and working, merging with master branch
This commit is contained in:
commit
5275da5a6b
@ -22,6 +22,7 @@ LIBS = libtoxcore ncursesw libconfig
|
|||||||
CFLAGS = -std=gnu99 -pthread -Wall -g
|
CFLAGS = -std=gnu99 -pthread -Wall -g
|
||||||
CFLAGS += -DTOXICVER="\"$(VERSION)\"" -DHAVE_WIDECHAR -D_XOPEN_SOURCE_EXTENDED
|
CFLAGS += -DTOXICVER="\"$(VERSION)\"" -DHAVE_WIDECHAR -D_XOPEN_SOURCE_EXTENDED
|
||||||
CFLAGS += -DPACKAGE_DATADIR="\"$(abspath $(DATADIR))\""
|
CFLAGS += -DPACKAGE_DATADIR="\"$(abspath $(DATADIR))\""
|
||||||
|
CFLAGS += -fdiagnostics-color
|
||||||
CFLAGS += $(USER_CFLAGS)
|
CFLAGS += $(USER_CFLAGS)
|
||||||
LDFLAGS = $(USER_LDFLAGS)
|
LDFLAGS = $(USER_LDFLAGS)
|
||||||
|
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
// SAMPLE TOXIC CONFIGURATION
|
|
||||||
// USES LIBCONFIG-ACCEPTED SYNTAX
|
|
||||||
|
|
||||||
ui = {
|
ui = {
|
||||||
// true to enable timestamps, false to disable
|
// true to enable timestamps, false to disable
|
||||||
@ -10,43 +8,22 @@ ui = {
|
|||||||
|
|
||||||
// true to use native terminal colours, false to use toxic default colour theme
|
// true to use native terminal colours, false to use toxic default colour theme
|
||||||
native_colors:false;
|
native_colors:false;
|
||||||
|
time_format=24;
|
||||||
// true to enable autologging, false to disable
|
autolog:false;
|
||||||
autolog:false;
|
|
||||||
|
|
||||||
// 24 or 12 hour time
|
|
||||||
time_format=24;
|
|
||||||
|
|
||||||
// maximum lines for chat window history
|
|
||||||
history_size=700;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
audio = {
|
//Only Ctrl modified keys and Tab supported right now
|
||||||
// preferred audio input device; numbers correspond to /lsdev in
|
//All printable keys register as input anyway
|
||||||
input_device=2;
|
keys = {
|
||||||
|
next_tab="Ctrl+P";
|
||||||
// preferred audio output device; numbers correspond to /lsdev out
|
//next_tab="Tab";
|
||||||
output_device=0;
|
prev_tab="Ctrl+O";
|
||||||
|
scroll_line_up="PAGEUP";
|
||||||
// default VAD treshold; float (recommended values are around 40)
|
scroll_line_down="PAGEDOWN";
|
||||||
VAD_treshold=40.0;
|
half_page_up="Ctrl+F";
|
||||||
|
half_page_down="Ctrl+V";
|
||||||
|
page_bottom="Ctrl+H";
|
||||||
|
peer_list_up="Ctrl+[";
|
||||||
|
peer_list_down="Ctrl+]";
|
||||||
};
|
};
|
||||||
|
|
||||||
tox = {
|
|
||||||
// where to store received files
|
|
||||||
// download_path="/home/USERNAME/Downloads/";
|
|
||||||
};
|
|
||||||
|
|
||||||
// To disable a sound set the path to "silent"
|
|
||||||
sounds = {
|
|
||||||
error="__DATADIR__/sounds/Error.wav";
|
|
||||||
self_log_in="__DATADIR__/sounds/LogIn.wav";
|
|
||||||
self_log_out="__DATADIR__/sounds/LogOut.wav";
|
|
||||||
user_log_in="__DATADIR__/sounds/ContactLogsIn.wav";
|
|
||||||
user_log_out="__DATADIR__/sounds/ContactLogsOut.wav";
|
|
||||||
call_incoming="__DATADIR__/sounds/IncomingCall.wav";
|
|
||||||
call_outgoing="__DATADIR__/sounds/OutgoingCall.wav";
|
|
||||||
generic_message="__DATADIR__/sounds/NewMessage.wav";
|
|
||||||
transfer_pending="__DATADIR__/sounds/TransferPending.wav";
|
|
||||||
transfer_completed="__DATADIR__/sounds/TransferComplete.wav";
|
|
||||||
};
|
|
||||||
|
@ -368,12 +368,12 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
|||||||
} else {
|
} else {
|
||||||
notify(self, error, 0);
|
notify(self, error, 0);
|
||||||
}
|
}
|
||||||
} else if (key == T_KEY_C_RB) { /* Scroll peerlist up and down one position */
|
} else if (key == user_settings_->key_peer_list_down) { /* Scroll peerlist up and down one position */
|
||||||
int L = y2 - CHATBOX_HEIGHT - SDBAR_OFST;
|
int L = y2 - CHATBOX_HEIGHT - SDBAR_OFST;
|
||||||
|
|
||||||
if (groupchats[self->num].side_pos < groupchats[self->num].num_peers - L)
|
if (groupchats[self->num].side_pos < groupchats[self->num].num_peers - L)
|
||||||
++groupchats[self->num].side_pos;
|
++groupchats[self->num].side_pos;
|
||||||
} else if (key == T_KEY_C_LB) {
|
} else if (key == user_settings_->key_peer_list_up) {
|
||||||
if (groupchats[self->num].side_pos > 0)
|
if (groupchats[self->num].side_pos > 0)
|
||||||
--groupchats[self->num].side_pos;
|
--groupchats[self->num].side_pos;
|
||||||
} else if (key == '\n') {
|
} else if (key == '\n') {
|
||||||
|
@ -460,35 +460,23 @@ bool line_info_onKey(ToxWindow *self, wint_t key)
|
|||||||
struct history *hst = self->chatwin->hst;
|
struct history *hst = self->chatwin->hst;
|
||||||
bool match = true;
|
bool match = true;
|
||||||
|
|
||||||
switch (key) {
|
if (key == user_settings_->key_half_page_up) {
|
||||||
/* TODO: Find good key bindings for all this stuff */
|
|
||||||
case T_KEY_C_F:
|
|
||||||
line_info_page_up(self, hst);
|
line_info_page_up(self, hst);
|
||||||
break;
|
}
|
||||||
|
else if(key == user_settings_->key_half_page_down) {
|
||||||
case T_KEY_C_V:
|
|
||||||
line_info_page_down(self, hst);
|
line_info_page_down(self, hst);
|
||||||
break;
|
}
|
||||||
|
else if(key == user_settings_->key_scroll_line_up) {
|
||||||
case KEY_PPAGE:
|
|
||||||
line_info_scroll_up(hst);
|
line_info_scroll_up(hst);
|
||||||
break;
|
}
|
||||||
|
else if(key == user_settings_->key_scroll_line_down) {
|
||||||
case KEY_NPAGE:
|
|
||||||
line_info_scroll_down(hst);
|
line_info_scroll_down(hst);
|
||||||
break;
|
}
|
||||||
|
else if(key == user_settings_->key_page_bottom) {
|
||||||
/* case ?:
|
|
||||||
line_info_goto_root(hst);
|
|
||||||
break; */
|
|
||||||
|
|
||||||
case T_KEY_C_H:
|
|
||||||
line_info_reset_start(self, hst);
|
line_info_reset_start(self, hst);
|
||||||
break;
|
}
|
||||||
|
else {
|
||||||
default:
|
|
||||||
match = false;
|
match = false;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return match;
|
return match;
|
||||||
|
@ -23,7 +23,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <libconfig.h>
|
#include <libconfig.h>
|
||||||
|
|
||||||
#include "toxic.h"
|
#include "toxic.h"
|
||||||
#include "windows.h"
|
#include "windows.h"
|
||||||
#include "configdir.h"
|
#include "configdir.h"
|
||||||
@ -68,7 +67,42 @@ static void ui_defaults(struct user_settings* settings)
|
|||||||
settings->colour_theme = DFLT_COLS;
|
settings->colour_theme = DFLT_COLS;
|
||||||
settings->history_size = 700;
|
settings->history_size = 700;
|
||||||
}
|
}
|
||||||
|
const struct _keys_strings {
|
||||||
|
const char* self;
|
||||||
|
const char* next_tab;
|
||||||
|
const char* prev_tab;
|
||||||
|
const char* scroll_line_up;
|
||||||
|
const char* scroll_line_down;
|
||||||
|
const char* half_page_up;
|
||||||
|
const char* half_page_down;
|
||||||
|
const char* page_bottom;
|
||||||
|
const char* peer_list_up;
|
||||||
|
const char* peer_list_down;
|
||||||
|
} key_strings = {
|
||||||
|
"keys",
|
||||||
|
"next_tab",
|
||||||
|
"prev_tab",
|
||||||
|
"scroll_line_up",
|
||||||
|
"scroll_line_down",
|
||||||
|
"half_page_up",
|
||||||
|
"half_page_down",
|
||||||
|
"page_bottom",
|
||||||
|
"peer_list_up",
|
||||||
|
"peer_list_down"
|
||||||
|
};
|
||||||
|
static void key_defaults(struct user_settings* settings)
|
||||||
|
{
|
||||||
|
settings->key_next_tab = 0x10;
|
||||||
|
settings->key_prev_tab = 0x0F;
|
||||||
|
settings->key_scroll_line_up = 0523; /* value from libncurses:curses.h */
|
||||||
|
settings->key_scroll_line_down = 0522;
|
||||||
|
settings->key_half_page_up = 0x06;
|
||||||
|
settings->key_half_page_down = 0x16;
|
||||||
|
settings->key_page_bottom = 0x08;
|
||||||
|
settings->key_peer_list_up = 0x1B;
|
||||||
|
settings->key_peer_list_down = 0x1D;
|
||||||
|
|
||||||
|
}
|
||||||
const struct _tox_strings {
|
const struct _tox_strings {
|
||||||
const char* self;
|
const char* self;
|
||||||
const char* download_path;
|
const char* download_path;
|
||||||
@ -139,6 +173,7 @@ int settings_load(struct user_settings *s, const char *patharg)
|
|||||||
/* Load default settings */
|
/* Load default settings */
|
||||||
ui_defaults(s);
|
ui_defaults(s);
|
||||||
tox_defaults(s);
|
tox_defaults(s);
|
||||||
|
key_defaults(s);
|
||||||
#ifdef _AUDIO
|
#ifdef _AUDIO
|
||||||
audio_defaults(s);
|
audio_defaults(s);
|
||||||
#endif
|
#endif
|
||||||
@ -155,7 +190,6 @@ int settings_load(struct user_settings *s, const char *patharg)
|
|||||||
|
|
||||||
/* make sure path exists or is created on first time running */
|
/* make sure path exists or is created on first time running */
|
||||||
FILE *fp = fopen(path, "r");
|
FILE *fp = fopen(path, "r");
|
||||||
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
if ((fp = fopen(path, "w")) == NULL)
|
if ((fp = fopen(path, "w")) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
@ -188,6 +222,19 @@ int settings_load(struct user_settings *s, const char *patharg)
|
|||||||
strcpy(s->download_path, str);
|
strcpy(s->download_path, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* keys */
|
||||||
|
if((setting = config_lookup(cfg, key_strings.self)) != NULL) {
|
||||||
|
const char* tmp = NULL;
|
||||||
|
if(config_setting_lookup_string(setting, key_strings.next_tab, &tmp)) s->key_next_tab = key_parse(&tmp);
|
||||||
|
if(config_setting_lookup_string(setting, key_strings.prev_tab, &tmp)) s->key_prev_tab = key_parse(&tmp);
|
||||||
|
if(config_setting_lookup_string(setting, key_strings.scroll_line_up, &tmp)) s->key_scroll_line_up = key_parse(&tmp);
|
||||||
|
if(config_setting_lookup_string(setting, key_strings.scroll_line_down, &tmp)) s->key_scroll_line_down= key_parse(&tmp);
|
||||||
|
if(config_setting_lookup_string(setting, key_strings.half_page_up, &tmp)) s->key_half_page_up = key_parse(&tmp);
|
||||||
|
if(config_setting_lookup_string(setting, key_strings.half_page_down, &tmp)) s->key_half_page_down = key_parse(&tmp);
|
||||||
|
if(config_setting_lookup_string(setting, key_strings.page_bottom, &tmp)) s->key_page_bottom = key_parse(&tmp);
|
||||||
|
if(config_setting_lookup_string(setting, key_strings.peer_list_up, &tmp)) s->key_peer_list_up = key_parse(&tmp);
|
||||||
|
if(config_setting_lookup_string(setting, key_strings.peer_list_down, &tmp)) s->key_peer_list_down = key_parse(&tmp);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _AUDIO
|
#ifdef _AUDIO
|
||||||
if ((setting = config_lookup(cfg, audio_strings.self)) != NULL) {
|
if ((setting = config_lookup(cfg, audio_strings.self)) != NULL) {
|
||||||
@ -280,3 +327,14 @@ int settings_load(struct user_settings *s, const char *patharg)
|
|||||||
config_destroy(cfg);
|
config_destroy(cfg);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
int key_parse(const char** bind){
|
||||||
|
if(strlen(*bind) > 5){
|
||||||
|
if(strncmp(*bind,"Ctrl+", 5)==0) return bind[0][5]-'A'+1;
|
||||||
|
}
|
||||||
|
if(strncmp(*bind,"Tab",3)==0) return 9;
|
||||||
|
if(strncmp(*bind,"PAGE",4)==0) {
|
||||||
|
if(strlen(*bind) == 6) return 0523;
|
||||||
|
return 0522;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
@ -33,6 +33,15 @@ struct user_settings {
|
|||||||
int history_size; /* int between MIN_HISTORY and MAX_HISTORY */
|
int history_size; /* int between MIN_HISTORY and MAX_HISTORY */
|
||||||
char download_path[MAX_STR_SIZE];
|
char download_path[MAX_STR_SIZE];
|
||||||
|
|
||||||
|
int key_next_tab; /* character code */
|
||||||
|
int key_prev_tab; /* character code */
|
||||||
|
int key_scroll_line_up;
|
||||||
|
int key_scroll_line_down;
|
||||||
|
int key_half_page_up;
|
||||||
|
int key_half_page_down;
|
||||||
|
int key_page_bottom;
|
||||||
|
int key_peer_list_up;
|
||||||
|
int key_peer_list_down;
|
||||||
#ifdef _AUDIO
|
#ifdef _AUDIO
|
||||||
int audio_in_dev;
|
int audio_in_dev;
|
||||||
int audio_out_dev;
|
int audio_out_dev;
|
||||||
@ -60,5 +69,5 @@ enum {
|
|||||||
} settings_values;
|
} settings_values;
|
||||||
|
|
||||||
int settings_load(struct user_settings *s, const char *patharg);
|
int settings_load(struct user_settings *s, const char *patharg);
|
||||||
|
int key_parse(const char** bind);
|
||||||
#endif /* #define _settings_h */
|
#endif /* #define _settings_h */
|
||||||
|
@ -33,15 +33,16 @@
|
|||||||
#include "chat.h"
|
#include "chat.h"
|
||||||
#include "line_info.h"
|
#include "line_info.h"
|
||||||
|
|
||||||
|
#include "settings.h"
|
||||||
extern char *DATA_FILE;
|
extern char *DATA_FILE;
|
||||||
extern struct _Winthread Winthread;
|
extern struct _Winthread Winthread;
|
||||||
static ToxWindow windows[MAX_WINDOWS_NUM];
|
static ToxWindow windows[MAX_WINDOWS_NUM];
|
||||||
static ToxWindow *active_window;
|
static ToxWindow *active_window;
|
||||||
|
|
||||||
extern ToxWindow *prompt;
|
extern ToxWindow *prompt;
|
||||||
|
extern struct user_settings *user_settings_;
|
||||||
|
|
||||||
static int num_active_windows;
|
static int num_active_windows;
|
||||||
|
|
||||||
/* CALLBACKS START */
|
/* CALLBACKS START */
|
||||||
void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
|
void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
|
||||||
{
|
{
|
||||||
@ -267,7 +268,7 @@ void set_next_window(int ch)
|
|||||||
ToxWindow *inf = active_window;
|
ToxWindow *inf = active_window;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (ch == T_KEY_NEXT) {
|
if (ch == user_settings_->key_next_tab) {
|
||||||
if (++active_window > end)
|
if (++active_window > end)
|
||||||
active_window = windows;
|
active_window = windows;
|
||||||
} else if (--active_window < windows)
|
} else if (--active_window < windows)
|
||||||
@ -452,7 +453,7 @@ void draw_active_window(Tox *m)
|
|||||||
ltr = isprint(ch);
|
ltr = isprint(ch);
|
||||||
#endif /* HAVE_WIDECHAR */
|
#endif /* HAVE_WIDECHAR */
|
||||||
|
|
||||||
if (!ltr && (ch == T_KEY_NEXT || ch == T_KEY_PREV)) {
|
if (!ltr && (ch == user_settings_->key_next_tab || ch == user_settings_->key_prev_tab)) {
|
||||||
set_next_window((int) ch);
|
set_next_window((int) ch);
|
||||||
} else {
|
} else {
|
||||||
pthread_mutex_lock(&Winthread.lock);
|
pthread_mutex_lock(&Winthread.lock);
|
||||||
|
Loading…
Reference in New Issue
Block a user