2014-06-22 02:18:23 +02:00
|
|
|
/* windows.h
|
2014-02-25 08:28:24 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Toxic All Rights Reserved.
|
|
|
|
*
|
|
|
|
* This file is part of Toxic.
|
|
|
|
*
|
|
|
|
* Toxic is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Toxic is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Toxic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
2013-07-31 20:20:16 +02:00
|
|
|
*/
|
2013-09-15 22:38:38 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifndef WINDOWS_H
|
|
|
|
#define WINDOWS_H
|
2013-07-31 20:20:16 +02:00
|
|
|
|
2014-04-08 12:09:42 +02:00
|
|
|
#include <pthread.h>
|
2014-09-22 20:27:33 +02:00
|
|
|
#include <signal.h>
|
2020-04-18 02:00:00 +02:00
|
|
|
#include <wchar.h>
|
|
|
|
#include <wctype.h>
|
2013-08-23 23:03:44 +02:00
|
|
|
|
2013-08-24 04:15:15 +02:00
|
|
|
#include <tox/tox.h>
|
2013-08-23 23:03:44 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-04-19 23:58:13 +02:00
|
|
|
#include <tox/toxav.h>
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2014-06-22 02:18:23 +02:00
|
|
|
#include "toxic.h"
|
2013-11-19 00:52:46 +01:00
|
|
|
|
2020-11-19 07:30:30 +01:00
|
|
|
#define MAX_WINDOWS_NUM 20
|
2014-11-15 21:55:45 +01:00
|
|
|
#define MAX_WINDOW_NAME_LENGTH 22
|
2014-06-22 02:18:23 +02:00
|
|
|
#define CURS_Y_OFFSET 1 /* y-axis cursor offset for chat contexts */
|
2020-11-30 05:26:51 +01:00
|
|
|
#define CHATBOX_HEIGHT 1
|
|
|
|
#define TOP_BAR_HEIGHT 1
|
|
|
|
#define WINDOW_BAR_HEIGHT 1
|
2013-12-06 04:55:14 +01:00
|
|
|
|
2021-01-17 19:29:13 +01:00
|
|
|
|
|
|
|
typedef enum CustomPacket {
|
|
|
|
CUSTOM_PACKET_GAME_INVITE = 160,
|
|
|
|
CUSTOM_PACKET_GAME_DATA = 161,
|
|
|
|
} CustomPacket;
|
|
|
|
|
|
|
|
|
2020-11-30 05:26:51 +01:00
|
|
|
/* ncurses colour pairs as FOREGROUND_BACKGROUND. No background defaults to black. */
|
2018-01-20 19:30:35 +01:00
|
|
|
typedef enum {
|
2013-11-10 07:23:07 +01:00
|
|
|
WHITE,
|
|
|
|
GREEN,
|
|
|
|
CYAN,
|
|
|
|
RED,
|
|
|
|
BLUE,
|
|
|
|
YELLOW,
|
|
|
|
MAGENTA,
|
|
|
|
BLACK,
|
2020-11-30 05:26:51 +01:00
|
|
|
BLACK_WHITE,
|
2020-12-11 07:46:01 +01:00
|
|
|
WHITE_BLACK,
|
|
|
|
WHITE_BLUE,
|
2020-12-19 21:40:00 +01:00
|
|
|
WHITE_GREEN,
|
2020-12-05 21:39:33 +01:00
|
|
|
BAR_TEXT,
|
|
|
|
STATUS_ONLINE,
|
|
|
|
BAR_ACCENT,
|
|
|
|
PURPLE_BG,
|
|
|
|
BLACK_BG,
|
|
|
|
STATUS_BUSY,
|
|
|
|
STATUS_AWAY,
|
|
|
|
BAR_NOTIFY,
|
2014-06-22 02:18:23 +02:00
|
|
|
} C_COLOURS;
|
2013-09-05 06:47:33 +02:00
|
|
|
|
2014-08-08 01:53:47 +02:00
|
|
|
/* tab alert types: lower types take priority (this relies on the order of C_COLOURS) */
|
2014-07-21 01:12:13 +02:00
|
|
|
typedef enum {
|
|
|
|
WINDOW_ALERT_NONE = 0,
|
2020-12-05 21:39:33 +01:00
|
|
|
WINDOW_ALERT_0 = STATUS_ONLINE,
|
|
|
|
WINDOW_ALERT_1 = BAR_ACCENT,
|
|
|
|
WINDOW_ALERT_2 = PURPLE_BG,
|
2014-06-22 02:18:23 +02:00
|
|
|
} WINDOW_ALERTS;
|
2014-03-24 12:18:58 +01:00
|
|
|
|
2020-11-09 23:01:22 +01:00
|
|
|
typedef enum {
|
|
|
|
WINDOW_TYPE_PROMPT,
|
|
|
|
WINDOW_TYPE_CHAT,
|
|
|
|
WINDOW_TYPE_CONFERENCE,
|
|
|
|
WINDOW_TYPE_FRIEND_LIST,
|
2021-01-19 04:37:14 +01:00
|
|
|
|
|
|
|
#ifdef GAMES
|
2020-12-11 07:46:01 +01:00
|
|
|
WINDOW_TYPE_GAME,
|
2021-01-19 04:37:14 +01:00
|
|
|
#endif
|
2020-11-09 23:01:22 +01:00
|
|
|
} WINDOW_TYPE;
|
|
|
|
|
2014-03-30 22:40:13 +02:00
|
|
|
/* Fixes text color problem on some terminals.
|
2013-09-26 15:51:21 +02:00
|
|
|
Uncomment if necessary */
|
2014-03-11 23:22:27 +01:00
|
|
|
/* #define URXVT_FIX */
|
2013-09-26 15:51:21 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
struct Winthread {
|
2014-06-22 02:18:23 +02:00
|
|
|
pthread_t tid;
|
|
|
|
pthread_mutex_t lock;
|
2014-09-22 20:27:33 +02:00
|
|
|
volatile sig_atomic_t sig_exit_toxic;
|
|
|
|
volatile sig_atomic_t flag_resize;
|
2014-06-22 02:18:23 +02:00
|
|
|
};
|
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
struct cqueue_thread {
|
2014-09-06 19:18:42 +02:00
|
|
|
pthread_t tid;
|
|
|
|
};
|
|
|
|
|
2015-08-10 13:14:38 +02:00
|
|
|
struct av_thread {
|
2014-11-29 05:51:32 +01:00
|
|
|
pthread_t tid;
|
|
|
|
};
|
|
|
|
|
2014-07-31 18:48:49 +02:00
|
|
|
struct arg_opts {
|
2015-03-26 03:56:45 +01:00
|
|
|
bool use_ipv4;
|
|
|
|
bool force_tcp;
|
2020-08-11 03:56:45 +02:00
|
|
|
bool disable_local_discovery;
|
2015-03-26 03:56:45 +01:00
|
|
|
bool debug;
|
|
|
|
bool default_locale;
|
|
|
|
bool use_custom_data;
|
|
|
|
bool no_connect;
|
|
|
|
bool encrypt_data;
|
|
|
|
bool unencrypt_data;
|
|
|
|
|
2015-10-28 22:14:17 +01:00
|
|
|
char nameserver_path[MAX_STR_SIZE];
|
2014-07-31 18:48:49 +02:00
|
|
|
char config_path[MAX_STR_SIZE];
|
|
|
|
char nodes_path[MAX_STR_SIZE];
|
2014-08-15 02:31:52 +02:00
|
|
|
|
2020-05-17 05:12:54 +02:00
|
|
|
bool logging;
|
|
|
|
FILE *log_fp;
|
|
|
|
|
2014-08-15 02:31:52 +02:00
|
|
|
char proxy_address[256];
|
2015-03-26 03:56:45 +01:00
|
|
|
uint8_t proxy_type;
|
2014-08-15 02:31:52 +02:00
|
|
|
uint16_t proxy_port;
|
2015-07-09 03:01:32 +02:00
|
|
|
|
|
|
|
uint16_t tcp_port;
|
2014-07-31 18:48:49 +02:00
|
|
|
};
|
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
typedef struct ToxWindow ToxWindow;
|
|
|
|
typedef struct StatusBar StatusBar;
|
2013-12-05 04:33:04 +01:00
|
|
|
typedef struct PromptBuf PromptBuf;
|
2013-11-29 23:48:08 +01:00
|
|
|
typedef struct ChatContext ChatContext;
|
2014-07-04 09:24:29 +02:00
|
|
|
typedef struct Help Help;
|
2021-01-19 04:37:14 +01:00
|
|
|
|
|
|
|
#ifdef GAMES
|
2020-12-11 07:46:01 +01:00
|
|
|
typedef struct GameData GameData;
|
2021-01-19 04:37:14 +01:00
|
|
|
#endif
|
2013-07-30 01:32:39 +02:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
struct ToxWindow {
|
2015-03-26 03:56:45 +01:00
|
|
|
/* ncurses */
|
2020-10-13 22:12:55 +02:00
|
|
|
bool(*onKey)(ToxWindow *, Tox *, wint_t, bool);
|
2013-08-23 23:03:44 +02:00
|
|
|
void(*onDraw)(ToxWindow *, Tox *);
|
|
|
|
void(*onInit)(ToxWindow *, Tox *);
|
2015-03-26 03:56:45 +01:00
|
|
|
|
|
|
|
/* toxcore */
|
|
|
|
void(*onFriendRequest)(ToxWindow *, Tox *, const char *, const char *, size_t);
|
|
|
|
void(*onFriendAdded)(ToxWindow *, Tox *, uint32_t, bool);
|
2018-10-10 05:06:57 +02:00
|
|
|
void(*onConnectionChange)(ToxWindow *, Tox *, uint32_t, Tox_Connection);
|
|
|
|
void(*onMessage)(ToxWindow *, Tox *, uint32_t, Tox_Message_Type, const char *, size_t);
|
2015-03-26 03:56:45 +01:00
|
|
|
void(*onNickChange)(ToxWindow *, Tox *, uint32_t, const char *, size_t);
|
2018-10-10 05:06:57 +02:00
|
|
|
void(*onStatusChange)(ToxWindow *, Tox *, uint32_t, Tox_User_Status);
|
2015-03-26 03:56:45 +01:00
|
|
|
void(*onStatusMessageChange)(ToxWindow *, uint32_t, const char *, size_t);
|
2020-11-08 16:08:24 +01:00
|
|
|
void(*onConferenceMessage)(ToxWindow *, Tox *, uint32_t, uint32_t, Tox_Message_Type, const char *, size_t);
|
|
|
|
void(*onConferenceInvite)(ToxWindow *, Tox *, int32_t, uint8_t, const char *, uint16_t);
|
|
|
|
void(*onConferenceNameListChange)(ToxWindow *, Tox *, uint32_t);
|
|
|
|
void(*onConferencePeerNameChange)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t);
|
|
|
|
void(*onConferenceTitleChange)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t);
|
2015-03-26 03:56:45 +01:00
|
|
|
void(*onFileChunkRequest)(ToxWindow *, Tox *, uint32_t, uint32_t, uint64_t, size_t);
|
|
|
|
void(*onFileRecvChunk)(ToxWindow *, Tox *, uint32_t, uint32_t, uint64_t, const char *, size_t);
|
2018-10-10 05:06:57 +02:00
|
|
|
void(*onFileControl)(ToxWindow *, Tox *, uint32_t, uint32_t, Tox_File_Control);
|
2015-03-30 00:33:51 +02:00
|
|
|
void(*onFileRecv)(ToxWindow *, Tox *, uint32_t, uint32_t, uint64_t, const char *, size_t);
|
2015-03-26 03:56:45 +01:00
|
|
|
void(*onTypingChange)(ToxWindow *, Tox *, uint32_t, bool);
|
|
|
|
void(*onReadReceipt)(ToxWindow *, Tox *, uint32_t, uint32_t);
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2021-01-19 04:37:14 +01:00
|
|
|
#ifdef GAMES
|
2021-01-17 19:29:13 +01:00
|
|
|
void(*onGameInvite)(ToxWindow *, Tox *, uint32_t, const uint8_t *, size_t);
|
|
|
|
void(*onGameData)(ToxWindow *, Tox *, uint32_t, const uint8_t *, size_t);
|
2021-01-19 04:37:14 +01:00
|
|
|
#endif // GAMES
|
2021-01-17 19:29:13 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-03-07 03:14:04 +01:00
|
|
|
|
2015-06-12 17:50:26 +02:00
|
|
|
void(*onInvite)(ToxWindow *, ToxAV *, uint32_t, int);
|
|
|
|
void(*onRinging)(ToxWindow *, ToxAV *, uint32_t, int);
|
|
|
|
void(*onStarting)(ToxWindow *, ToxAV *, uint32_t, int);
|
|
|
|
void(*onEnding)(ToxWindow *, ToxAV *, uint32_t, int);
|
|
|
|
void(*onError)(ToxWindow *, ToxAV *, uint32_t, int);
|
|
|
|
void(*onStart)(ToxWindow *, ToxAV *, uint32_t, int);
|
|
|
|
void(*onCancel)(ToxWindow *, ToxAV *, uint32_t, int);
|
|
|
|
void(*onReject)(ToxWindow *, ToxAV *, uint32_t, int);
|
|
|
|
void(*onEnd)(ToxWindow *, ToxAV *, uint32_t, int);
|
|
|
|
void(*onWriteDevice)(ToxWindow *, Tox *, uint32_t, int, const int16_t *, unsigned int, uint8_t, unsigned int);
|
|
|
|
|
2015-07-03 21:39:27 +02:00
|
|
|
bool is_call;
|
2014-08-02 00:37:02 +02:00
|
|
|
int ringing_sound;
|
2015-07-30 08:49:27 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2014-03-30 22:40:13 +02:00
|
|
|
|
2014-08-02 00:37:02 +02:00
|
|
|
int active_box; /* For box notify */
|
2015-03-26 03:56:45 +01:00
|
|
|
|
2014-10-03 23:53:50 +02:00
|
|
|
char name[TOXIC_MAX_NAME_LENGTH + 1];
|
2015-07-06 22:43:05 +02:00
|
|
|
uint32_t num; /* corresponds to friendnumber in chat windows */
|
2018-10-10 00:59:25 +02:00
|
|
|
uint8_t index; /* This window's index in the windows array */
|
2020-11-30 05:26:51 +01:00
|
|
|
bool scroll_pause; /* true if this window is not scrolled to the bottom */
|
2020-11-21 17:25:41 +01:00
|
|
|
unsigned int pending_messages; /* # of new messages in this window since the last time it was focused */
|
2013-12-07 02:56:30 +01:00
|
|
|
int x;
|
|
|
|
|
2020-11-09 23:01:22 +01:00
|
|
|
WINDOW_TYPE type;
|
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
int show_peerlist; /* used to toggle conference peerlist */
|
2014-02-26 11:23:11 +01:00
|
|
|
|
2014-07-21 01:12:13 +02:00
|
|
|
WINDOW_ALERTS alert;
|
2013-09-07 01:59:45 +02:00
|
|
|
|
2013-11-29 23:48:08 +01:00
|
|
|
ChatContext *chatwin;
|
|
|
|
StatusBar *stb;
|
2014-07-04 09:24:29 +02:00
|
|
|
Help *help;
|
2013-08-16 19:11:09 +02:00
|
|
|
|
2021-01-19 04:37:14 +01:00
|
|
|
#ifdef GAMES
|
2020-12-11 07:46:01 +01:00
|
|
|
GameData *game;
|
2021-01-19 04:37:14 +01:00
|
|
|
#endif
|
2020-12-11 07:46:01 +01:00
|
|
|
|
2013-08-16 19:11:09 +02:00
|
|
|
WINDOW *window;
|
2020-11-30 05:26:51 +01:00
|
|
|
WINDOW *window_bar;
|
2013-07-30 01:32:39 +02:00
|
|
|
};
|
2013-08-11 02:58:15 +02:00
|
|
|
|
2013-12-05 04:33:04 +01:00
|
|
|
/* statusbar info holder */
|
2013-11-29 23:48:08 +01:00
|
|
|
struct StatusBar {
|
2014-03-30 22:40:13 +02:00
|
|
|
WINDOW *topline;
|
2015-03-26 03:56:45 +01:00
|
|
|
char statusmsg[TOX_MAX_STATUS_MESSAGE_LENGTH + 1];
|
|
|
|
size_t statusmsg_len;
|
2014-10-03 23:53:50 +02:00
|
|
|
char nick[TOXIC_MAX_NAME_LENGTH + 1];
|
2015-03-26 03:56:45 +01:00
|
|
|
size_t nick_len;
|
2018-10-10 05:06:57 +02:00
|
|
|
Tox_User_Status status;
|
|
|
|
Tox_Connection connection;
|
2013-11-29 23:48:08 +01:00
|
|
|
};
|
2013-09-06 08:51:10 +02:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-07-01 17:17:52 +02:00
|
|
|
|
|
|
|
#define INFOBOX_HEIGHT 7
|
|
|
|
#define INFOBOX_WIDTH 21
|
2015-03-26 03:56:45 +01:00
|
|
|
|
2014-06-24 00:54:23 +02:00
|
|
|
/* holds display info for audio calls */
|
|
|
|
struct infobox {
|
|
|
|
float vad_lvl;
|
|
|
|
bool in_is_muted;
|
|
|
|
bool out_is_muted;
|
|
|
|
bool hide;
|
|
|
|
bool active;
|
|
|
|
|
2016-09-23 00:31:52 +02:00
|
|
|
time_t lastupdate;
|
|
|
|
time_t starttime;
|
2014-06-24 00:54:23 +02:00
|
|
|
char timestr[TIME_STR_SIZE];
|
|
|
|
|
|
|
|
WINDOW *win;
|
|
|
|
};
|
2014-09-23 03:24:45 +02:00
|
|
|
#endif /* AUDIO */
|
2014-06-24 00:54:23 +02:00
|
|
|
|
2013-12-19 02:18:38 +01:00
|
|
|
#define MAX_LINE_HIST 128
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2020-11-08 16:08:24 +01:00
|
|
|
/* chat and conference window/buffer holder */
|
2013-11-29 23:48:08 +01:00
|
|
|
struct ChatContext {
|
2013-09-15 22:38:38 +02:00
|
|
|
wchar_t line[MAX_STR_SIZE];
|
2014-06-26 08:33:09 +02:00
|
|
|
int pos;
|
|
|
|
int len;
|
|
|
|
int start; /* the position to start printing line at */
|
2013-12-11 06:10:09 +01:00
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
wchar_t ln_history[MAX_LINE_HIST][MAX_STR_SIZE]; /* history for input lines/commands */
|
2013-12-11 06:10:09 +01:00
|
|
|
int hst_pos;
|
|
|
|
int hst_tot;
|
|
|
|
|
2014-07-14 20:32:38 +02:00
|
|
|
wchar_t yank[MAX_STR_SIZE]; /* contains last killed/discarded line */
|
|
|
|
int yank_len;
|
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
struct history *hst;
|
2014-03-01 13:10:44 +01:00
|
|
|
struct chatlog *log;
|
2014-09-06 19:18:42 +02:00
|
|
|
struct chat_queue *cqueue;
|
2014-03-24 12:37:52 +01:00
|
|
|
|
2014-09-23 03:24:45 +02:00
|
|
|
#ifdef AUDIO
|
2014-06-24 00:54:23 +02:00
|
|
|
struct infobox infobox;
|
|
|
|
#endif
|
|
|
|
|
2014-03-24 12:18:58 +01:00
|
|
|
uint8_t self_is_typing;
|
2016-01-17 15:10:46 +01:00
|
|
|
uint8_t pastemode; /* whether to translate \r to \n */
|
2014-02-26 07:51:06 +01:00
|
|
|
|
2013-09-15 22:38:38 +02:00
|
|
|
WINDOW *history;
|
|
|
|
WINDOW *linewin;
|
2013-11-24 03:19:59 +01:00
|
|
|
WINDOW *sidebar;
|
2013-12-05 04:33:04 +01:00
|
|
|
};
|
|
|
|
|
2014-07-04 09:24:29 +02:00
|
|
|
struct Help {
|
|
|
|
WINDOW *win;
|
|
|
|
int type;
|
|
|
|
bool active;
|
|
|
|
};
|
|
|
|
|
2013-11-30 11:35:25 +01:00
|
|
|
ToxWindow *init_windows(Tox *m);
|
2013-08-23 23:03:44 +02:00
|
|
|
void draw_active_window(Tox *m);
|
2018-10-10 00:59:25 +02:00
|
|
|
int add_window(Tox *m, ToxWindow *w);
|
2013-08-17 10:00:19 +02:00
|
|
|
void del_window(ToxWindow *w);
|
2018-10-10 00:59:25 +02:00
|
|
|
void set_active_window_index(uint8_t index);
|
2014-03-07 01:39:57 +01:00
|
|
|
int get_num_active_windows(void);
|
2014-08-05 23:38:33 +02:00
|
|
|
void kill_all_windows(Tox *m); /* should only be called on shutdown */
|
2014-07-01 05:56:47 +02:00
|
|
|
void on_window_resize(void);
|
2014-10-01 22:24:36 +02:00
|
|
|
void force_refresh(WINDOW *w);
|
2018-10-10 00:59:25 +02:00
|
|
|
ToxWindow *get_window_ptr(size_t i);
|
2017-05-17 02:31:23 +02:00
|
|
|
ToxWindow *get_active_window(void);
|
2020-11-30 05:26:51 +01:00
|
|
|
void draw_window_bar(ToxWindow *self);
|
2014-02-26 11:23:11 +01:00
|
|
|
|
2015-03-26 03:56:45 +01:00
|
|
|
/* refresh inactive windows to prevent scrolling bugs.
|
2014-06-22 03:41:38 +02:00
|
|
|
call at least once per second */
|
|
|
|
void refresh_inactive_windows(void);
|
|
|
|
|
2021-06-28 19:54:25 +02:00
|
|
|
#endif // WINDOWS_H
|
2020-12-19 21:40:00 +01:00
|
|
|
|