1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-06-29 16:07:47 +02:00
toxic/src/windows.h

270 lines
7.3 KiB
C
Raw Normal View History

/* 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-09-15 22:38:38 +02:00
#ifndef WINDOWS_H
#define WINDOWS_H
#include <pthread.h>
#include <wctype.h>
#include <wchar.h>
#include <signal.h>
2013-08-23 23:03:44 +02:00
#include <tox/tox.h>
2013-08-23 23:03:44 +02:00
#ifdef AUDIO
#include <tox/toxav.h>
#endif /* AUDIO */
2014-03-07 03:14:04 +01:00
#include "toxic.h"
2013-11-19 00:52:46 +01:00
#define MAX_WINDOWS_NUM 32
2014-11-15 21:55:45 +01:00
#define MAX_WINDOW_NAME_LENGTH 22
#define CURS_Y_OFFSET 1 /* y-axis cursor offset for chat contexts */
#define CHATBOX_HEIGHT 2
2013-12-06 04:55:14 +01:00
/* Curses foreground colours (background is black) */
typedef enum {
2013-11-10 07:23:07 +01:00
WHITE,
GREEN,
CYAN,
RED,
BLUE,
YELLOW,
MAGENTA,
BLACK,
} C_COLOURS;
/* 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,
WINDOW_ALERT_0 = GREEN,
WINDOW_ALERT_1 = RED,
WINDOW_ALERT_2 = MAGENTA,
} WINDOW_ALERTS;
2014-03-30 22:40:13 +02:00
/* Fixes text color problem on some terminals.
Uncomment if necessary */
/* #define URXVT_FIX */
struct Winthread {
pthread_t tid;
pthread_mutex_t lock;
volatile sig_atomic_t sig_exit_toxic;
volatile sig_atomic_t flag_resize;
};
struct cqueue_thread {
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;
bool debug;
bool default_locale;
bool use_custom_data;
bool no_connect;
bool encrypt_data;
bool unencrypt_data;
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
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;
uint16_t tcp_port;
2014-07-31 18:48:49 +02:00
};
typedef struct ToxWindow ToxWindow;
typedef struct StatusBar StatusBar;
typedef struct PromptBuf PromptBuf;
typedef struct ChatContext ChatContext;
typedef struct Help Help;
struct ToxWindow {
2015-03-26 03:56:45 +01:00
/* ncurses */
2014-03-30 22:40:13 +02:00
void(*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);
void(*onConnectionChange)(ToxWindow *, Tox *, uint32_t, TOX_CONNECTION);
void(*onMessage)(ToxWindow *, Tox *, uint32_t, TOX_MESSAGE_TYPE, const char *, size_t);
void(*onNickChange)(ToxWindow *, Tox *, uint32_t, const char *, size_t);
void(*onStatusChange)(ToxWindow *, Tox *, uint32_t, TOX_USER_STATUS);
void(*onStatusMessageChange)(ToxWindow *, uint32_t, const char *, size_t);
2016-12-18 06:01:51 +01:00
void(*onGroupMessage)(ToxWindow *, Tox *, uint32_t, uint32_t, TOX_MESSAGE_TYPE, const char *, size_t);
2014-11-12 00:30:23 +01:00
void(*onGroupInvite)(ToxWindow *, Tox *, int32_t, uint8_t, const char *, uint16_t);
void(*onGroupNameListChange)(ToxWindow *, Tox *, uint32_t);
void(*onGroupPeerNameChange)(ToxWindow *, Tox *, uint32_t, uint32_t, const char *, size_t);
2016-12-18 06:01:51 +01:00
void(*onGroupTitleChange)(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);
void(*onFileControl)(ToxWindow *, Tox *, uint32_t, uint32_t, TOX_FILE_CONTROL);
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
#ifdef AUDIO
2014-03-07 03:14:04 +01: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);
2014-06-21 01:58:00 +02:00
int device_selection[2]; /* -1 if not set, if set uses these selections instead of primary device */
bool is_call;
2014-08-02 00:37:02 +02:00
int ringing_sound;
#ifdef VIDEO
int video_device_selection[2]; /* -1 if not set, if set uses these selections instead of primary video device */
#endif /* VIDEO */
#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];
uint32_t num; /* corresponds to friendnumber in chat windows */
bool active;
2013-12-07 02:56:30 +01:00
int x;
2014-02-26 11:23:11 +01:00
bool is_chat;
2014-03-02 00:06:35 +01:00
bool is_prompt;
bool is_friendlist;
bool is_groupchat;
int show_peerlist; /* used to toggle groupchat peerlist */
2014-02-26 11:23:11 +01:00
2014-07-21 01:12:13 +02:00
WINDOW_ALERTS alert;
ChatContext *chatwin;
StatusBar *stb;
Help *help;
2013-08-16 19:11:09 +02:00
WINDOW *window;
};
/* statusbar info holder */
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;
TOX_USER_STATUS status;
TOX_CONNECTION connection;
};
#ifdef AUDIO
#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;
time_t lastupdate;
time_t starttime;
2014-06-24 00:54:23 +02:00
char timestr[TIME_STR_SIZE];
WINDOW *win;
};
#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
/* chat and groupchat window/buffer holder */
struct ChatContext {
2013-09-15 22:38:38 +02:00
wchar_t line[MAX_STR_SIZE];
int pos;
int len;
int start; /* the position to start printing line at */
2013-12-11 06:10:09 +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;
wchar_t yank[MAX_STR_SIZE]; /* contains last killed/discarded line */
int yank_len;
struct history *hst;
struct chatlog *log;
struct chat_queue *cqueue;
#ifdef AUDIO
2014-06-24 00:54:23 +02:00
struct infobox infobox;
#endif
uint8_t self_is_typing;
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;
WINDOW *sidebar;
};
struct Help {
WINDOW *win;
int type;
bool active;
};
ToxWindow *init_windows(Tox *m);
2013-08-23 23:03:44 +02:00
void draw_active_window(Tox *m);
int add_window(Tox *m, ToxWindow w);
void del_window(ToxWindow *w);
void set_active_window(int ch);
2014-03-07 01:39:57 +01:00
int get_num_active_windows(void);
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);
ToxWindow *get_window_ptr(int i);
ToxWindow *get_active_window(void);
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);
#endif /* #define WINDOWS_H */