int BC_Pan::button_press_event() { // there are two modes of operation... if (popup) { if (popup->is_event_win() && get_button_down() && get_buttonpress() == 1) { active = 1; x_origin = popup->get_cursor_x(); y_origin = popup->get_cursor_y(); stick_x_origin = stick_x; stick_y_origin = stick_y; return 1; } else { deactivate(); return 0; } } if(is_event_win() && get_button_down() && get_buttonpress() == 1) { hide_tooltip(); activate(); active = 1; x_origin = get_cursor_x(); y_origin = get_cursor_y(); stick_x_origin = stick_x; stick_y_origin = stick_y; draw_popup(); return 1; } return 0; }
void *window_action_listener(void *ctx) { popup_window *win = (popup_window *)ctx; XEvent xe; XSelectInput(win->dsp, win->win, LeaveWindowMask); event: draw_popup(win); XNextEvent(win->dsp, &xe); if (xe.type != LeaveNotify) { goto event; } (win->free_reference)(); return NULL; }
int BC_Pan::cursor_motion_event() { if(popup && get_button_down() && get_buttonpress() == 1) { stick_x = stick_x_origin + get_cursor_x() - x_origin; stick_y = stick_y_origin + get_cursor_y() - y_origin; CLAMP(stick_x, 0, virtual_r * 2); CLAMP(stick_y, 0, virtual_r * 2); stick_to_values(); draw_popup(); handle_event(); return 1; } return 0; }
int BC_Pan::activate(int popup_x, int popup_y) { int x, y; Window tempwin; active = 0; if (popup_x < 0 || popup_y < 0) { XTranslateCoordinates(top_level->display, win, top_level->rootwin, 0, 0, &x, &y, &tempwin); x -= (images[PAN_POPUP]->get_w() - get_w()) / 2; y -= (images[PAN_POPUP]->get_h() - get_h()) / 2; if (x < 0) x = 0; } else { XTranslateCoordinates(top_level->display, top_level->win, top_level->rootwin, popup_x, popup_y, &x, &y, &tempwin); x -= images[PAN_POPUP]->get_w() / 2; y -= images[PAN_POPUP]->get_h() / 2; if (x < 0) x = 0; } delete popup; popup = new BC_Popup(this, x, y, images[PAN_POPUP]->get_w(), images[PAN_POPUP]->get_h(), 0, 0, images[PAN_POPUP]); draw_popup(); flush(); return 0; }
static void friendlist_onDraw(ToxWindow *self, Tox *m) { curs_set(0); werase(self->window); int x2, y2; getmaxyx(self->window, y2, x2); bool fix_statuses = x2 != self->x; /* true if window x axis has changed */ wattron(self->window, COLOR_PAIR(CYAN)); wprintw(self->window, " Open a chat window with the"); wattron(self->window, A_BOLD); wprintw(self->window, " Enter "); wattroff(self->window, A_BOLD); wprintw(self->window, "key. Delete a friend with the"); wattron(self->window, A_BOLD); wprintw(self->window, " Delete "); wattroff(self->window, A_BOLD); wprintw(self->window, "key.\n\n"); wattroff(self->window, COLOR_PAIR(CYAN)); wattron(self->window, A_BOLD); wprintw(self->window, " Online: %d/%d \n\n", tox_get_num_online_friends(m), num_friends); wattroff(self->window, A_BOLD); if ((y2 - FLIST_OFST) <= 0) /* don't allow division by zero */ return; /* Determine which portion of friendlist to draw based on current position */ int page = num_selected / (y2 - FLIST_OFST); int start = (y2 - FLIST_OFST) * page; int end = y2 - FLIST_OFST + start; int i; for (i = start; i < num_friends && i < end; ++i) { int f = friendlist_index[i]; bool f_selected = false; if (friends[f].active) { if (i == num_selected) { wattron(self->window, A_BOLD); wprintw(self->window, " > "); wattroff(self->window, A_BOLD); f_selected = true; } else { wprintw(self->window, " "); } if (friends[f].online) { TOX_USERSTATUS status = friends[f].status; int colour = WHITE; switch (status) { case TOX_USERSTATUS_NONE: colour = GREEN; break; case TOX_USERSTATUS_AWAY: colour = YELLOW; break; case TOX_USERSTATUS_BUSY: colour = RED; break; } wprintw(self->window, "["); wattron(self->window, COLOR_PAIR(colour) | A_BOLD); wprintw(self->window, "O"); wattroff(self->window, COLOR_PAIR(colour) | A_BOLD); wprintw(self->window, "]"); if (f_selected) wattron(self->window, A_BOLD); wprintw(self->window, "%s", friends[f].name); if (f_selected) wattroff(self->window, A_BOLD); /* Reset friends[f].statusmsg on window resize */ if (fix_statuses) { uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'}; tox_get_status_message(m, friends[f].num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH); snprintf(friends[f].statusmsg, sizeof(friends[f].statusmsg), "%s", statusmsg); friends[f].statusmsg_len = tox_get_status_message_size(m, f); } /* Truncate note if it doesn't fit on one line */ uint16_t maxlen = x2 - getcurx(self->window) - 4; if (friends[f].statusmsg_len > maxlen) { friends[f].statusmsg[maxlen-3] = '\0'; strcat(friends[f].statusmsg, "..."); friends[f].statusmsg[maxlen] = '\0'; friends[f].statusmsg_len = maxlen; } wprintw(self->window, " (%s)\n", friends[f].statusmsg); } else { wprintw(self->window, "["); wattron(self->window, A_BOLD); wprintw(self->window, "O"); wattroff(self->window, A_BOLD); wprintw(self->window, "]"); if (f_selected) wattron(self->window, A_BOLD); wprintw(self->window, "%s\n", friends[f].name); if (f_selected) wattroff(self->window, A_BOLD); } } } self->x = x2; wrefresh(self->window); draw_popup(self, m); }
static void friendlist_onDraw(ToxWindow *self, Tox *m) { curs_set(0); werase(self->window); int x2, y2; getmaxyx(self->window, y2, x2); uint64_t cur_time = get_unix_time(); struct tm cur_loc_tm = *localtime(&cur_time); bool fix_statuses = x2 != self->x; /* true if window x axis has changed */ wattron(self->window, COLOR_PAIR(CYAN)); wprintw(self->window, " Open a chat window with the"); wattron(self->window, A_BOLD); wprintw(self->window, " Enter "); wattroff(self->window, A_BOLD); wprintw(self->window, "key. Delete a friend with the"); wattron(self->window, A_BOLD); wprintw(self->window, " Delete "); wattroff(self->window, A_BOLD); wprintw(self->window, "key.\n\n"); wattroff(self->window, COLOR_PAIR(CYAN)); pthread_mutex_lock(&Winthread.lock); int nf = tox_get_num_online_friends(m); pthread_mutex_unlock(&Winthread.lock); wattron(self->window, A_BOLD); wprintw(self->window, " Online: "); wattroff(self->window, A_BOLD); wprintw(self->window, "%d/%d \n\n", nf, num_friends); if ((y2 - FLIST_OFST) <= 0) /* don't allow division by zero */ return; int selected_num = 0; /* Determine which portion of friendlist to draw based on current position */ int page = num_selected / (y2 - FLIST_OFST); int start = (y2 - FLIST_OFST) * page; int end = y2 - FLIST_OFST + start; int i; for (i = start; i < num_friends && i < end; ++i) { int f = friendlist_index[i]; bool f_selected = false; if (friends[f].active) { if (i == num_selected) { wattron(self->window, A_BOLD); wprintw(self->window, " > "); wattroff(self->window, A_BOLD); selected_num = f; f_selected = true; } else { wprintw(self->window, " "); } if (friends[f].online) { uint8_t status = friends[f].status; int colour = WHITE; switch (status) { case TOX_USERSTATUS_NONE: colour = GREEN; break; case TOX_USERSTATUS_AWAY: colour = YELLOW; break; case TOX_USERSTATUS_BUSY: colour = RED; break; case TOX_USERSTATUS_INVALID: colour = MAGENTA; break; } wattron(self->window, COLOR_PAIR(colour) | A_BOLD); wprintw(self->window, "O "); wattroff(self->window, COLOR_PAIR(colour) | A_BOLD); if (f_selected) wattron(self->window, COLOR_PAIR(BLUE)); wattron(self->window, A_BOLD); wprintw(self->window, "%s", friends[f].name); wattroff(self->window, A_BOLD); if (f_selected) wattroff(self->window, COLOR_PAIR(BLUE)); /* Reset friends[f].statusmsg on window resize */ if (fix_statuses) { uint8_t statusmsg[TOX_MAX_STATUSMESSAGE_LENGTH] = {'\0'}; pthread_mutex_lock(&Winthread.lock); uint16_t s_len = tox_get_status_message(m, friends[f].num, statusmsg, TOX_MAX_STATUSMESSAGE_LENGTH); pthread_mutex_unlock(&Winthread.lock); friends[f].statusmsg_len = s_len; friends[f].statusmsg[s_len] = '\0'; snprintf(friends[f].statusmsg, sizeof(friends[f].statusmsg), "%s", statusmsg); } /* Truncate note if it doesn't fit on one line */ uint16_t maxlen = x2 - getcurx(self->window) - 2; if (friends[f].statusmsg_len > maxlen) { friends[f].statusmsg[maxlen - 3] = '\0'; strcat(friends[f].statusmsg, "..."); friends[f].statusmsg[maxlen] = '\0'; friends[f].statusmsg_len = maxlen; } if (friends[f].statusmsg[0]) wprintw(self->window, " %s", friends[f].statusmsg); wprintw(self->window, "\n"); } else { wprintw(self->window, "o "); if (f_selected) wattron(self->window, COLOR_PAIR(BLUE)); wattron(self->window, A_BOLD); wprintw(self->window, "%s", friends[f].name); wattroff(self->window, A_BOLD); if (f_selected) wattroff(self->window, COLOR_PAIR(BLUE)); uint64_t last_seen = friends[f].last_online.last_on; if (last_seen != 0) { int day_dist = (cur_loc_tm.tm_yday - friends[f].last_online.tm.tm_yday) % 365; const uint8_t *hourmin = friends[f].last_online.hour_min_str; switch (day_dist) { case 0: wprintw(self->window, " Last seen: Today %s\n", hourmin); break; case 1: wprintw(self->window, " Last seen: Yesterday %s\n", hourmin); break; default: wprintw(self->window, " Last seen: %d days ago\n", day_dist); break; } } else { wprintw(self->window, " Last seen: Never\n"); } } } } self->x = x2; wrefresh(self->window); draw_popup(self, m); if (num_friends) { wmove(self->window, y2 - 1, 1); wattron(self->window, A_BOLD); wprintw(self->window, "ID: "); wattroff(self->window, A_BOLD); int i; for (i = 0; i < TOX_CLIENT_ID_SIZE; ++i) wprintw(self->window, "%02X", friends[selected_num].pub_key[i] & 0xff); } }