Skip to content

Commit

Permalink
refactor: x11 focus object is no longer global
Browse files Browse the repository at this point in the history
  • Loading branch information
JFreegman committed Feb 4, 2024
1 parent ea90877 commit 5ad00f7
Show file tree
Hide file tree
Showing 16 changed files with 179 additions and 169 deletions.
58 changes: 27 additions & 31 deletions src/chat.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,36 +176,37 @@ void kill_chat_window(ToxWindow *self, Toxic *toxic)
del_window(self, toxic->c_config);
}

static void recv_message_helper(ToxWindow *self, const Client_Config *c_config, const char *msg,
static void recv_message_helper(ToxWindow *self, const Toxic *toxic, const char *msg,
const char *nick)
{
const Client_Config *c_config = toxic->c_config;
ChatContext *ctx = self->chatwin;

line_info_add(self, c_config, true, nick, NULL, IN_MSG, 0, 0, "%s", msg);
write_to_log(ctx->log, c_config, msg, nick, false);

if (self->active_box != -1) {
box_notify2(self, c_config, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | c_config->bell_on_message,
box_notify2(self, toxic, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | c_config->bell_on_message,
self->active_box, "%s", msg);
} else {
box_notify(self, c_config, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | c_config->bell_on_message,
box_notify(self, toxic, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | c_config->bell_on_message,
&self->active_box, nick, "%s", msg);
}
}

static void recv_action_helper(ToxWindow *self, const Client_Config *c_config, const char *action,
const char *nick)
static void recv_action_helper(ToxWindow *self, const Toxic *toxic, const char *action, const char *nick)
{
const Client_Config *c_config = toxic->c_config;
ChatContext *ctx = self->chatwin;

line_info_add(self, c_config, true, nick, NULL, IN_ACTION, 0, 0, "%s", action);
write_to_log(ctx->log, c_config, action, nick, true);

if (self->active_box != -1) {
box_notify2(self, c_config, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | c_config->bell_on_message,
box_notify2(self, toxic, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | c_config->bell_on_message,
self->active_box, "* %s %s", nick, action);
} else {
box_notify(self, c_config, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | c_config->bell_on_message,
box_notify(self, toxic, generic_message, NT_WNDALERT_1 | NT_NOFOCUS | c_config->bell_on_message,
&self->active_box, self->name, "* %s %s", nick, action);
}
}
Expand All @@ -219,8 +220,6 @@ static void chat_onMessage(ToxWindow *self, Toxic *toxic, uint32_t num, Tox_Mess
return;
}

const Client_Config *c_config = toxic->c_config;

if (self->num != num) {
return;
}
Expand All @@ -229,12 +228,12 @@ static void chat_onMessage(ToxWindow *self, Toxic *toxic, uint32_t num, Tox_Mess
get_nick_truncate(toxic->tox, nick, num);

if (type == TOX_MESSAGE_TYPE_NORMAL) {
recv_message_helper(self, c_config, msg, nick);
recv_message_helper(self, toxic, msg, nick);
return;
}

if (type == TOX_MESSAGE_TYPE_ACTION) {
recv_action_helper(self, c_config, msg, nick);
recv_action_helper(self, toxic, msg, nick);
return;
}
}
Expand Down Expand Up @@ -572,8 +571,7 @@ static void chat_onFileControl(ToxWindow *self, Toxic *toxic, uint32_t friendnum
ft->state = FILE_TRANSFER_STARTED;
line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "File transfer [%zu] for '%s' accepted.",
ft->index, ft->file_name);
sound_notify(self, c_config, silent,
NT_NOFOCUS | c_config->bell_on_filetrans_accept | NT_WNDALERT_2, NULL);
sound_notify(self, toxic, silent, NT_NOFOCUS | c_config->bell_on_filetrans_accept | NT_WNDALERT_2, NULL);
} else if (ft->state == FILE_TRANSFER_PAUSED) { /* transfer is resumed */
ft->state = FILE_TRANSFER_STARTED;
}
Expand Down Expand Up @@ -785,10 +783,10 @@ static void chat_onFileRecv(ToxWindow *self, Toxic *toxic, uint32_t friendnum, u
free(file_path);

if (self->active_box != -1) {
box_notify2(self, c_config, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS | c_config->bell_on_filetrans,
box_notify2(self, toxic, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS | c_config->bell_on_filetrans,
self->active_box, "Incoming file: %s", filename);
} else {
box_notify(self, c_config, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS | c_config->bell_on_filetrans,
box_notify(self, toxic, transfer_pending, NT_WNDALERT_0 | NT_NOFOCUS | c_config->bell_on_filetrans,
&self->active_box, self->name, "Incoming file: %s", filename);
}

Expand Down Expand Up @@ -843,11 +841,10 @@ static void chat_onConferenceInvite(ToxWindow *self, Toxic *toxic, int32_t frien
const char *description = type == TOX_CONFERENCE_TYPE_AV ? "an audio conference" : "a conference";

if (self->active_box != -1) {
box_notify2(self, c_config, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, self->active_box,
box_notify2(self, toxic, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, self->active_box,
"invites you to join %s", description);
} else {
box_notify(self, c_config, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, &self->active_box,
name,
box_notify(self, toxic, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, &self->active_box, name,
"invites you to join %s", description);
}

Expand Down Expand Up @@ -884,16 +881,16 @@ static void chat_onGroupInvite(ToxWindow *self, Toxic *toxic, uint32_t friendnum
memcpy(Friends.list[friendnumber].group_invite.data, invite_data, length);
Friends.list[friendnumber].group_invite.length = length;

sound_notify(self, c_config, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, NULL);
sound_notify(self, toxic, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, NULL);

char name[TOX_MAX_NAME_LENGTH];
get_nick_truncate(toxic->tox, name, friendnumber);

if (self->active_box != -1) {
box_silent_notify2(self, c_config, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box,
box_silent_notify2(self, toxic, NT_WNDALERT_2 | NT_NOFOCUS, self->active_box,
"invites you to join group chat");
} else {
box_silent_notify(self, c_config, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name,
box_silent_notify(self, toxic, NT_WNDALERT_2 | NT_NOFOCUS, &self->active_box, name,
"invites you to join group chat");
}

Expand Down Expand Up @@ -967,10 +964,10 @@ static void chat_onGameInvite(ToxWindow *self, Toxic *toxic, uint32_t friend_num
get_nick_truncate(toxic->tox, name, friend_number);

if (self->active_box != -1) {
box_notify2(self, c_config, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, self->active_box,
box_notify2(self, toxic, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, self->active_box,
"invites you to play %s", game_string);
} else {
box_notify(self, c_config, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, &self->active_box,
box_notify(self, toxic, generic_message, NT_WNDALERT_2 | c_config->bell_on_invite, &self->active_box,
name,
"invites you to play %s", game_string);
}
Expand Down Expand Up @@ -1007,14 +1004,13 @@ static void chat_onInvite(ToxWindow *self, Toxic *toxic, uint32_t friend_number,
"Incoming audio call! Type: \"/answer\" or \"/reject\"");

if (self->ringing_sound == -1) {
sound_notify(self, c_config, call_incoming, NT_LOOP | c_config->bell_on_invite, &self->ringing_sound);
sound_notify(self, toxic, call_incoming, NT_LOOP | c_config->bell_on_invite, &self->ringing_sound);
}

if (self->active_box != -1) {
box_silent_notify2(self, c_config, NT_NOFOCUS | NT_WNDALERT_0, self->active_box, "Incoming audio call!");
box_silent_notify2(self, toxic, NT_NOFOCUS | NT_WNDALERT_0, self->active_box, "Incoming audio call!");
} else {
box_silent_notify(self, c_config, NT_NOFOCUS | NT_WNDALERT_0, &self->active_box, self->name,
"Incoming audio call!");
box_silent_notify(self, toxic, NT_NOFOCUS | NT_WNDALERT_0, &self->active_box, self->name, "Incoming audio call!");
}
}

Expand All @@ -1038,7 +1034,7 @@ static void chat_onRinging(ToxWindow *self, Toxic *toxic, uint32_t friend_number
#ifdef SOUND_NOTIFY

if (self->ringing_sound == -1) {
sound_notify(self, c_config, call_outgoing, NT_LOOP, &self->ringing_sound);
sound_notify(self, toxic, call_outgoing, NT_LOOP, &self->ringing_sound);
}

#endif /* SOUND_NOTIFY */
Expand Down Expand Up @@ -1326,7 +1322,7 @@ static bool chat_onKey(ToxWindow *self, Toxic *toxic, wint_t key, bool ltr)
}

if (ltr || key == L'\n') { /* char is printable */
input_new_char(self, c_config, key, x, x2);
input_new_char(self, toxic, key, x, x2);

if (ctx->line[0] != '/' && !ctx->self_is_typing && statusbar->connection != TOX_CONNECTION_NONE) {
set_self_typingstatus(self, toxic, true);
Expand All @@ -1339,7 +1335,7 @@ static bool chat_onKey(ToxWindow *self, Toxic *toxic, wint_t key, bool ltr)
return true;
}

bool input_ret = input_handle(self, c_config, key, x, x2);
bool input_ret = input_handle(self, toxic, key, x, x2);

if (key == L'\t' && ctx->len > 1 && ctx->line[0] == '/') { /* TAB key: auto-complete */
input_ret = true;
Expand Down Expand Up @@ -1369,7 +1365,7 @@ static bool chat_onKey(ToxWindow *self, Toxic *toxic, wint_t key, bool ltr)
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
}
} else {
sound_notify(self, c_config, notif_error, 0, NULL);
sound_notify(self, toxic, notif_error, 0, NULL);
}

} else if (key == L'\r') {
Expand Down
14 changes: 7 additions & 7 deletions src/conference.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,16 @@ static void conference_onConferenceMessage(ToxWindow *self, Toxic *toxic, uint32
/* Only play sound if mentioned by someone else */
if (strcasestr(msg, selfnick) && strcmp(selfnick, nick)) {
if (self->active_box != -1) {
box_notify2(self, c_config, generic_message, NT_WNDALERT_0 | NT_NOFOCUS | c_config->bell_on_message,
box_notify2(self, toxic, generic_message, NT_WNDALERT_0 | NT_NOFOCUS | c_config->bell_on_message,
self->active_box, "%s %s", nick, msg);
} else {
box_notify(self, c_config, generic_message, NT_WNDALERT_0 | NT_NOFOCUS | c_config->bell_on_message,
box_notify(self, toxic, generic_message, NT_WNDALERT_0 | NT_NOFOCUS | c_config->bell_on_message,
&self->active_box, self->name, "%s %s", nick, msg);
}

nick_clr = RED;
} else {
sound_notify(self, c_config, silent, NT_WNDALERT_1, NULL);
sound_notify(self, toxic, silent, NT_WNDALERT_1, NULL);
}

line_info_add(self, c_config, true, nick, NULL, type == TOX_MESSAGE_TYPE_NORMAL ? IN_MSG : IN_ACTION, 0,
Expand Down Expand Up @@ -915,15 +915,15 @@ static bool conference_onKey(ToxWindow *self, Toxic *toxic, wint_t key, bool ltr
}

if (ltr || key == L'\n') { /* char is printable */
input_new_char(self, c_config, key, x, x2);
input_new_char(self, toxic, key, x, x2);
return true;
}

if (line_info_onKey(self, c_config, key)) {
return true;
}

if (input_handle(self, c_config, key, x, x2)) {
if (input_handle(self, toxic, key, x, x2)) {
return true;
}

Expand Down Expand Up @@ -998,10 +998,10 @@ static bool conference_onKey(ToxWindow *self, Toxic *toxic, wint_t key, bool ltr
ctx->start = wlen < x2 ? 0 : wlen - x2 + 1;
}
} else {
sound_notify(self, c_config, notif_error, 0, NULL);
sound_notify(self, toxic, notif_error, 0, NULL);
}
} else {
sound_notify(self, c_config, notif_error, 0, NULL);
sound_notify(self, toxic, notif_error, 0, NULL);
}
} else if (key == T_KEY_C_DOWN) { /* Scroll peerlist up and down one position */
input_ret = true;
Expand Down
8 changes: 3 additions & 5 deletions src/file_transfers.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,6 @@ int file_send_queue_remove(uint32_t friendnumber, size_t index)
void close_file_transfer(ToxWindow *self, const Toxic *toxic, FileTransfer *ft, int CTRL, const char *message,
Notification sound_type)
{
const Client_Config *c_config = toxic->c_config;

if (ft == NULL) {
return;
}
Expand All @@ -359,12 +357,12 @@ void close_file_transfer(ToxWindow *self, const Toxic *toxic, FileTransfer *ft,

if (message && self) {
if (self->active_box != -1 && sound_type != silent) {
box_notify2(self, c_config, sound_type, NT_NOFOCUS | NT_WNDALERT_2, self->active_box, "%s", message);
box_notify2(self, toxic, sound_type, NT_NOFOCUS | NT_WNDALERT_2, self->active_box, "%s", message);
} else {
box_notify(self, c_config, sound_type, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box, self->name, "%s", message);
box_notify(self, toxic, sound_type, NT_NOFOCUS | NT_WNDALERT_2, &self->active_box, self->name, "%s", message);
}

line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", message);
line_info_add(self, toxic->c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%s", message);
}

clear_file_transfer(ft);
Expand Down
14 changes: 7 additions & 7 deletions src/friendlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ static void friendlist_onMessage(ToxWindow *self, Toxic *toxic, uint32_t num, To
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED,
"* Warning: Too many windows are open.");

sound_notify(home_window, c_config, notif_error, NT_WNDALERT_1, NULL);
sound_notify(home_window, toxic, notif_error, NT_WNDALERT_1, NULL);
}

static void friendlist_onConnectionChange(ToxWindow *self, Toxic *toxic, uint32_t num, Tox_Connection connection_status)
Expand Down Expand Up @@ -661,7 +661,7 @@ static void friendlist_onGameInvite(ToxWindow *self, Toxic *toxic, uint32_t frie
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED,
"* Game invite from %s failed: Too many windows are open.", nick);

sound_notify(home_window, c_config, notif_error, NT_WNDALERT_1, NULL);
sound_notify(home_window, toxic, notif_error, NT_WNDALERT_1, NULL);
}

#endif // GAMES
Expand Down Expand Up @@ -699,7 +699,7 @@ static void friendlist_onFileRecv(ToxWindow *self, Toxic *toxic, uint32_t num, u
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED,
"* File transfer from %s failed: too many windows are open.", nick);

sound_notify(home_window, c_config, notif_error, NT_WNDALERT_1, NULL);
sound_notify(home_window, toxic, notif_error, NT_WNDALERT_1, NULL);
}

static void friendlist_onConferenceInvite(ToxWindow *self, Toxic *toxic, int32_t num, uint8_t type,
Expand Down Expand Up @@ -738,7 +738,7 @@ static void friendlist_onConferenceInvite(ToxWindow *self, Toxic *toxic, int32_t
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED,
"* Conference chat invite from %s failed: too many windows are open.", nick);

sound_notify(home_window, c_config, notif_error, NT_WNDALERT_1, NULL);
sound_notify(home_window, toxic, notif_error, NT_WNDALERT_1, NULL);
}

static void friendlist_onGroupInvite(ToxWindow *self, Toxic *toxic, uint32_t num, const char *data, size_t length,
Expand Down Expand Up @@ -775,7 +775,7 @@ static void friendlist_onGroupInvite(ToxWindow *self, Toxic *toxic, uint32_t num
line_info_add(home_window, c_config, NULL, NULL, NULL, SYS_MSG, 0, RED,
"* Group chat invite from %s failed: too many windows are open.", nick);

sound_notify(home_window, c_config, notif_error, NT_WNDALERT_1, NULL);
sound_notify(home_window, toxic, notif_error, NT_WNDALERT_1, NULL);
}

/* move friendlist/blocklist cursor up and down */
Expand Down Expand Up @@ -1069,7 +1069,7 @@ static bool friendlist_onKey(ToxWindow *self, Toxic *toxic, wint_t key, bool ltr
} else {
const char *msg = "* Warning: Too many windows are open.";
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED, msg);
sound_notify(home_window, c_config, notif_error, NT_WNDALERT_1, NULL);
sound_notify(home_window, toxic, notif_error, NT_WNDALERT_1, NULL);
}

break;
Expand Down Expand Up @@ -1468,7 +1468,7 @@ static void friendlist_onAV(ToxWindow *self, Toxic *toxic, uint32_t friend_numbe
const char *errmsg = "* Warning: Too many windows are open.";
line_info_add(home_window, c_config, false, NULL, NULL, SYS_MSG, 0, RED, errmsg);

sound_notify(home_window, c_config, notif_error, NT_WNDALERT_1, NULL);
sound_notify(home_window, toxic, notif_error, NT_WNDALERT_1, NULL);
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/game_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,16 @@ void game_window_notify(const GameData *game, const char *message)
return;
}

const Client_Config *c_config = game->toxic->c_config;
const Toxic *toxic = game->toxic;
const Client_Config *c_config = toxic->c_config;

const int bell_on_message = c_config->bell_on_message;

if (self->active_box != -1) {
box_notify2(self, c_config, generic_message, NT_WNDALERT_0 | NT_NOFOCUS | bell_on_message,
box_notify2(self, toxic, generic_message, NT_WNDALERT_0 | NT_NOFOCUS | bell_on_message,
self->active_box, "%s", message);
} else {
box_notify(self, c_config, generic_message, NT_WNDALERT_0 | NT_NOFOCUS | bell_on_message,
box_notify(self, toxic, generic_message, NT_WNDALERT_0 | NT_NOFOCUS | bell_on_message,
&self->active_box, self->name, "%s", message);
}
}
Expand Down
Loading

0 comments on commit 5ad00f7

Please sign in to comment.