Пример #1
0
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
{
    if (num_friends == 0)
        return;

    int f = friendlist_index[num_selected];

    if (key == '\n') {
        /* Jump to chat window if already open */
        if (friends[f].chatwin != -1) {
            set_active_window(friends[f].chatwin);
        } else if (num_active_windows() < MAX_WINDOWS_NUM) {
            friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
            set_active_window(friends[f].chatwin);
        } else {
            prep_prompt_win();
            wattron(prompt->window, COLOR_PAIR(RED));
            wprintw(prompt->window, "* Warning: Too many windows are open.\n");
            wattron(prompt->window, COLOR_PAIR(RED));

            alert_window(prompt, WINDOW_ALERT_1, true);
        }
    } else if (key == KEY_DC) {
        delete_friend(m, self, f, key);
    } else {
        select_friend(self, m, key);
    }
}
/*******************************************************************
 *		set_foreground_window
 */
static BOOL set_foreground_window( HWND hwnd, BOOL mouse )
{
    BOOL ret, send_msg_old = FALSE, send_msg_new = FALSE;
    HWND previous = 0;

    SERVER_START_REQ( set_foreground_window )
    {
        req->handle = wine_server_user_handle( hwnd );
        if ((ret = !wine_server_call_err( req )))
        {
            previous = wine_server_ptr_handle( reply->previous );
            send_msg_old = reply->send_msg_old;
            send_msg_new = reply->send_msg_new;
        }
    }
    SERVER_END_REQ;

    if (ret && previous != hwnd)
    {
        if (send_msg_old)  /* old window belongs to other thread */
            SendNotifyMessageW( previous, WM_WINE_SETACTIVEWINDOW, 0, 0 );
        else if (send_msg_new)  /* old window belongs to us but new one to other thread */
            ret = set_active_window( 0, NULL, mouse, TRUE );

        if (send_msg_new)  /* new window belongs to other thread */
            SendNotifyMessageW( hwnd, WM_WINE_SETACTIVEWINDOW, (WPARAM)hwnd, 0 );
        else  /* new window belongs to us */
            ret = set_active_window( hwnd, NULL, mouse, TRUE );
    }
    return ret;
}
Пример #3
0
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
{
    if (key == KEY_UP || key == KEY_DOWN) {
        select_friend(m, key);
    } else if (key == '\n') {
        /* Jump to chat window if already open */
        if (friends[num_selected].chatwin != -1) {
            set_active_window(friends[num_selected].chatwin);
        } else {
            friends[num_selected].chatwin = add_window(m, new_chat(m, prompt, friends[num_selected].num));
            set_active_window(friends[num_selected].chatwin);
        }
    } else if (key == 0x107 || key == 0x8 || key == 0x7f)
        delete_friend(m, self, num_selected, key);
}
Пример #4
0
static void friendlist_onAV(ToxWindow *self, ToxAV *av, uint32_t friend_number, int state)
{
    assert(0);
    if( friend_number >= Friends.max_idx)
        return;

    assert(0);
    Tox *m = toxav_get_tox(av);

    if (Friends.list[friend_number].chatwin == -1) {
        if (get_num_active_windows() < MAX_WINDOWS_NUM) {
            if(state != TOXAV_FRIEND_CALL_STATE_FINISHED) {
                Friends.list[friend_number].chatwin = add_window(m, new_chat(m, Friends.list[friend_number].num));
                set_active_window(Friends.list[friend_number].chatwin);
            }
        } else {
            char nick[TOX_MAX_NAME_LENGTH];
            get_nick_truncate(m, nick, Friends.list[friend_number].num);
            line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, 0, "Audio action from: %s!", nick);

            const char *errmsg = "* Warning: Too many windows are open.";
            line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, errmsg);

            sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
        }
    }
}
/*******************************************************************
 *		SetActiveWindow (USER32.@)
 */
HWND WINAPI SetActiveWindow( HWND hwnd )
{
    HWND prev;

    TRACE( "%p\n", hwnd );

    if (hwnd)
    {
        LONG style;

        hwnd = WIN_GetFullHandle( hwnd );
        if (!IsWindow( hwnd ))
        {
            SetLastError( ERROR_INVALID_WINDOW_HANDLE );
            return 0;
        }

        style = GetWindowLongW( hwnd, GWL_STYLE );
        if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD)
            return GetActiveWindow();  /* Windows doesn't seem to return an error here */
    }

    if (!set_active_window( hwnd, &prev, FALSE, TRUE )) return 0;
    return prev;
}
Пример #6
0
static void delete_friend(Tox *m, int32_t f_num)
{
    int i;

    if (friends[f_num].chatwin >= 0) {
        ToxWindow *toxwin = get_window_ptr(friends[f_num].chatwin);

        if (toxwin != NULL) {
            kill_chat_window(toxwin);
            set_active_window(1);   /* keep friendlist focused */
        }
    }

    tox_del_friend(m, f_num);
    memset(&friends[f_num], 0, sizeof(ToxicFriend));

    for (i = max_friends_index; i > 0; --i) {
        if (friends[i - 1].active)
            break;
    }

    max_friends_index = i;
    num_friends = tox_count_friendlist(m);

    /* make sure num_selected stays within num_friends range */
    if (num_friends && num_selected == num_friends)
        --num_selected;

    store_data(m, DATA_FILE);
}
Пример #7
0
static void delete_friend(Tox *m, int32_t f_num)
{
    if (Friends.list[f_num].chatwin >= 0) {
        ToxWindow *toxwin = get_window_ptr(Friends.list[f_num].chatwin);

        if (toxwin != NULL) {
            kill_chat_window(toxwin, m);
            set_active_window(1);   /* keep friendlist focused */
        }
    }

    if (Friends.list[f_num].group_invite.key != NULL)
        free(Friends.list[f_num].group_invite.key);

    tox_del_friend(m, f_num);
    memset(&Friends.list[f_num], 0, sizeof(ToxicFriend));

    int i;

    for (i = Friends.max_idx; i > 0; --i) {
        if (Friends.list[i - 1].active)
            break;
    }

    Friends.max_idx = i;
    Friends.num_friends = tox_count_friendlist(m);
    realloc_friends(i);

    /* make sure num_selected stays within Friends.num_friends range */
    if (Friends.num_friends && Friends.num_selected == Friends.num_friends)
        --Friends.num_selected;

    store_data(m, DATA_FILE);
}
Пример #8
0
// internally used only (in above function)
static void on_activate_plot_window(
	GtkObject *object,
	gpointer user_data)
{
	gint window_index= GPOINTER_TO_INT(user_data);
	
	fprintf(stderr, "Activate plot window %d\n", window_index);
	set_active_window(window_index, TRUE);
}
Пример #9
0
static void
window_closed (WnckScreen* screen,
               WnckWindow* window,
               gpointer    user_data)
{
  if (window == PRIV (user_data)->active)
    {
      set_active_window (user_data, NULL);
    }
}
/*****************************************************************
 *		SetFocus  (USER32.@)
 */
HWND WINAPI SetFocus( HWND hwnd )
{
    HWND hwndTop = hwnd;
    HWND previous = GetFocus();

    TRACE( "%p prev %p\n", hwnd, previous );

    if (hwnd)
    {
        /* Check if we can set the focus to this window */
        hwnd = WIN_GetFullHandle( hwnd );
        if (!IsWindow( hwnd ))
        {
            SetLastError( ERROR_INVALID_WINDOW_HANDLE );
            return 0;
        }
        if (hwnd == previous) return previous;  /* nothing to do */
        for (;;)
        {
            HWND parent;
            LONG style = GetWindowLongW( hwndTop, GWL_STYLE );
            if (style & (WS_MINIMIZE | WS_DISABLED)) return 0;
            if (!(style & WS_CHILD)) break;
            parent = GetAncestor( hwndTop, GA_PARENT );
            if (!parent || parent == GetDesktopWindow())
            {
                if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return 0;
                break;
            }
            if (parent == get_hwnd_message_parent()) return 0;
            hwndTop = parent;
        }

        /* call hooks */
        if (HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)hwnd, (LPARAM)previous, TRUE )) return 0;

        /* activate hwndTop if needed. */
        if (hwndTop != GetActiveWindow())
        {
            if (!set_active_window( hwndTop, NULL, FALSE, FALSE )) return 0;
            if (!IsWindow( hwnd )) return 0;  /* Abort if window destroyed */

            /* Do not change focus if the window is no longer active */
            if (hwndTop != GetActiveWindow()) return 0;
        }
    }
    else /* NULL hwnd passed in */
    {
        if (!previous) return 0;  /* nothing to do */
        if (HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, 0, (LPARAM)previous, TRUE )) return 0;
    }

    /* change focus and send messages */
    return set_focus_window( hwnd );
}
Пример #11
0
int main(int argc, char *argv[])
{
  int ch;
  int f_flag = 0;
  char *filename = "data";
  ToxWindow* a;

  int i = 0;
  for (i = 0; i < argc; ++i) {
    if (argv[i] == NULL)
      break;
    else if (argv[i][0] == '-') {
      if (argv[i][1] == 'f') {
        if (argv[i + 1] != NULL)
          filename = argv[i + 1];
        else
          f_flag = -1;
      }
    }
  }

  init_term();
  init_tox();
  load_data(filename);
  init_windows();
  init_window_status();

  if (f_flag == -1) {
    attron(COLOR_PAIR(3) | A_BOLD);
    wprintw(prompt->window, "You passed '-f' without giving an argument!\n"
                            "defaulting to 'data' for a keyfile...\n");
    attroff(COLOR_PAIR(3) | A_BOLD);
  }
  
  while(true) {
    /* Update tox */
    do_tox();

    /* Draw */
    a = &windows[active_window];
    prepare_window(a->window);
    a->blink = false;
    draw_bar();
    a->onDraw(a);

    /* Handle input */
    ch = getch();
    if (ch == '\t' || ch == KEY_BTAB)
      set_active_window(ch);
    else if (ch != ERR)
      a->onKey(a, ch);
  }
  return 0;
}
Пример #12
0
/* Deletes window w and cleans up */
void del_window(ToxWindow *w)
{
    set_active_window(0);    /* Go to prompt screen */

    delwin(w->window);
    memset(w, 0, sizeof(ToxWindow));

    clear();
    refresh();
    --num_active_windows;
}
Пример #13
0
static void
active_window_changed (WnckScreen* screen,
                       WnckWindow* previous,
                       gpointer    user_data)
{
  WorkspaceButton* self = user_data;
  WnckWindow     * current = wnck_screen_get_active_window (screen);

  if (current && wnck_window_is_on_workspace (current, PRIV (self)->workspace) &&
      wnck_screen_get_active_workspace (screen) == PRIV (self)->workspace)
    {
      set_active_window (self, current);
    }
}
Пример #14
0
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key)
{
    if (num_friends == 0)
        return;

    int f = friendlist_index[num_selected];

    /* lock screen and force decision on deletion popup */
    if (pendingdelete.active) {
        if (key == 'y' || key == 'n')
            del_friend_deactivate(self, m, key);

        return;
    }

    if (key == '\n') {
        /* Jump to chat window if already open */
        if (friends[f].chatwin != -1) {
            set_active_window(friends[f].chatwin);
        } else if (get_num_active_windows() < MAX_WINDOWS_NUM) {
            friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
            set_active_window(friends[f].chatwin);
        } else {
            prep_prompt_win();
            wattron(prompt->window, COLOR_PAIR(RED));
            wprintw(prompt->window, "* Warning: Too many windows are open.\n");
            wattron(prompt->window, COLOR_PAIR(RED));

            alert_window(prompt, WINDOW_ALERT_1, true);
        }
    } else if (key == KEY_DC) {
        del_friend_activate(self, m, f);
    } else {
        select_friend(self, m, key);
    }
}
Пример #15
0
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
{
    if (num_friends == 0)
        return;

    int f = friendlist_index[num_selected];

    /* lock screen and force decision on deletion popup */
    if (pendingdelete.active) {
        if (key == 'y' || key == 'n')
            del_friend_deactivate(self, m, key);

        return;
    }

    if (key != ltr) {
        if (key == '\n') {
            /* Jump to chat window if already open */
            if (friends[f].chatwin != -1) {
                set_active_window(friends[f].chatwin);
            } else if (get_num_active_windows() < MAX_WINDOWS_NUM) {
                friends[f].chatwin = add_window(m, new_chat(m, friends[f].num));
                set_active_window(friends[f].chatwin);
            } else {
                uint8_t *msg = "* Warning: Too many windows are open.";
                line_info_add(prompt, NULL, NULL, NULL, msg, SYS_MSG, 0, RED);

                alert_window(prompt, WINDOW_ALERT_1, true);
            }
        } else if (key == KEY_DC) {
            del_friend_activate(self, m, f);
        } else {
            select_friend(self, m, key);
        }
    }
}
Пример #16
0
void draw_active_window(Messenger * m)
{

    ToxWindow *a = &windows[active_window];
    prepare_window(a->window);
    a->blink = false;
    draw_bar();
    a->onDraw(a);

    /* Handle input */
    int ch = getch();
    if (ch == '\t' || ch == KEY_BTAB)
        set_active_window(ch);
    else if (ch != ERR)
        a->onKey(a, m, ch);
}
Пример #17
0
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum, uint8_t type)
{
    if (groupnum > MAX_GROUPCHAT_NUM)
        return -1;

    ToxWindow self = new_group_chat(m, groupnum);
    int i;

    for (i = 0; i <= max_groupchat_index; ++i) {
        if (!groupchats[i].active) {
            groupchats[i].chatwin = add_window(m, self);
            groupchats[i].active = true;
            groupchats[i].num_peers = 0;
            groupchats[i].type = type;
            groupchats[i].start_time = get_unix_time();

            groupchats[i].peer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH);
            groupchats[i].oldpeer_names = malloc(sizeof(uint8_t) * TOX_MAX_NAME_LENGTH);
            groupchats[i].peer_name_lengths = malloc(sizeof(uint16_t));
            groupchats[i].oldpeer_name_lengths = malloc(sizeof(uint16_t));

            if (groupchats[i].peer_names == NULL || groupchats[i].oldpeer_names == NULL
                || groupchats[i].peer_name_lengths == NULL || groupchats[i].oldpeer_name_lengths == NULL)
                exit_toxic_err("failed in init_groupchat_win", FATALERR_MEMORY);

            memcpy(&groupchats[i].oldpeer_names[0], UNKNOWN_NAME, sizeof(UNKNOWN_NAME));
            groupchats[i].oldpeer_name_lengths[0] = (uint16_t) strlen(UNKNOWN_NAME);

#ifdef AUDIO
            if (type == TOX_GROUPCHAT_TYPE_AV) {
                if (group_audio_open_out_device(i) != 0)
                    fprintf(stderr, "audio failed\n");
            }
#endif /* AUDIO */

            set_active_window(groupchats[i].chatwin);

            if (i == max_groupchat_index)
                ++max_groupchat_index;

            return 0;
        }
    }

    return -1;
}
Пример #18
0
static void delete_friend(Tox *m, uint32_t f_num)
{
    TOX_ERR_FRIEND_DELETE err;
    if (tox_friend_delete(m, f_num, &err) != true) {
        fprintf(stderr, "tox_friend_delete failed with error %d\n", err);
        return;
    }

    --Friends.num_friends;

    if (Friends.list[f_num].connection_status != TOX_CONNECTION_NONE)
        --Friends.num_online;

    /* close friend's chatwindow if it's currently open */
    if (Friends.list[f_num].chatwin >= 0) {
        ToxWindow *toxwin = get_window_ptr(Friends.list[f_num].chatwin);

        if (toxwin != NULL) {
            kill_chat_window(toxwin, m);
            set_active_window(1);   /* keep friendlist focused */
        }
    }

    if (Friends.list[f_num].group_invite.key != NULL)
        free(Friends.list[f_num].group_invite.key);

    memset(&Friends.list[f_num], 0, sizeof(ToxicFriend));

    int i;

    for (i = Friends.max_idx; i > 0; --i) {
        if (Friends.list[i - 1].active)
            break;
    }

    Friends.max_idx = i;
    realloc_friends(i);

    /* make sure num_selected stays within Friends.num_friends range */
    if (Friends.num_friends && Friends.num_selected == Friends.num_friends)
        --Friends.num_selected;

    store_data(m, DATA_FILE);
}
Пример #19
0
int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum)
{
    int i;

    for (i = 0; i <= group_chat_index; ++i) {
        if (!groupchats[i].active) {
            groupchats[i].chatwin = add_window(m, new_group_chat(m, prompt, groupnum));
            groupchats[i].active = true;
            set_active_window(groupchats[i].chatwin);

            if (i == group_chat_index)
                ++group_chat_index;

            return 0;
        }
    }

    return -1;
}
Пример #20
0
/*** RELEASE REFERENCES TO WIDGETS OF SPECIFIED APPLICATION ***
 *
 * When an application exists, we need to prevent further references to
 * widgets of the application, for example the mouse focus. Therefore,
 * this function should be called on application exit.
 */
static void release_app(int app_id) {

	if (curr_selected && (curr_selected->gen->get_app_id(curr_selected) == app_id))
		idle();

	if (curr_window && (curr_window->gen->get_app_id((WIDGET *)curr_window) == app_id))
		set_active_window(NULL, 1);

	if (curr_mfocus && (curr_mfocus->gen->get_app_id(curr_mfocus) == app_id)) {
		curr_mfocus->gen->dec_ref(curr_mfocus);
		curr_mfocus = NULL;
	}

	if (curr_receiver && (curr_receiver->gen->get_app_id(curr_receiver) == app_id)) {
		curr_receiver->gen->dec_ref(curr_receiver);
		curr_receiver = NULL;
	}

	curr_receiver = NULL;
	curr_selected = NULL;
	curr_window   = NULL;
	curr_mfocus   = NULL;
}
Пример #21
0
static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key)
{
    ChatContext *ctx = (ChatContext *) self->chatwin;
    struct tm *timeinfo = get_time();

    int x, y, y2, x2;
    getyx(self->window, y, x);
    getmaxyx(self->window, y2, x2);

    /* BACKSPACE key: Remove one character from line */
    if (key == 0x107 || key == 0x8 || key == 0x7f) {
        if (ctx->pos > 0) {
            ctx->line[--ctx->pos] = L'\0';

            if (x == 0)
                mvwdelch(self->window, y - 1, x2 - 1);
            else
                mvwdelch(self->window, y, x - 1);
        }
    } else 
    /* Add printable chars to buffer and print on input space */
#if HAVE_WIDECHAR
    if (iswprint(key)) {
#else
    if (isprint(key)) {
#endif
        if (ctx->pos < (MAX_STR_SIZE-1)) {
            mvwaddstr(self->window, y, x, wc_to_char(key));
            ctx->line[ctx->pos++] = key;
            ctx->line[ctx->pos] = L'\0';
        }
    }

    /* RETURN key: Execute command or print line */
    else if (key == '\n') {
        uint8_t *line = wcs_to_char(ctx->line);
        wclear(ctx->linewin);
        wmove(self->window, y2 - CURS_Y_OFFSET, 0);
        wclrtobot(self->window);
        bool close_win = false;

        if (line[0] == '/') {
            if (close_win = strncmp(line, "/close", strlen("/close")) == 0) {
                set_active_window(0);
                int groupnum = self->num;
                delwin(ctx->linewin);
                del_window(self);
                close_groupchatwin(m, groupnum);
            } else if (strncmp(line, "/help", strlen("/help")) == 0)
                print_groupchat_help(ctx);
              else
                execute(ctx->history, self->prompt, m, line, ctx->pos);
        } else {
            /* make sure the string has at least non-space character */
            if (!string_is_empty(line)) {
                // uint8_t selfname[TOX_MAX_NAME_LENGTH];
                // tox_getselfname(m, selfname, TOX_MAX_NAME_LENGTH);

                // wattron(ctx->history, COLOR_PAIR(CYAN));
                // wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
                // wattroff(ctx->history, COLOR_PAIR(CYAN));
                // wattron(ctx->history, COLOR_PAIR(GREEN));
                // wprintw(ctx->history, "%s: ", selfname);
                // wattroff(ctx->history, COLOR_PAIR(GREEN));
                // wprintw(ctx->history, "%s\n", line);

                if (tox_group_message_send(m, self->num, line, strlen(line) + 1) == -1) {
                    wattron(ctx->history, COLOR_PAIR(RED));
                    wprintw(ctx->history, " * Failed to send message.\n");
                    wattroff(ctx->history, COLOR_PAIR(RED));
                }
            }
        }

        if (close_win)
            free(ctx);
        else {
            ctx->line[0] = L'\0';
            ctx->pos = 0;
        }

        free(line);
    }
}

static void groupchat_onDraw(ToxWindow *self, Tox *m)
{
    curs_set(1);
    int x, y;
    getmaxyx(self->window, y, x);
    ChatContext *ctx = (ChatContext *) self->chatwin;
    mvwhline(ctx->linewin, 0, 0, '_', x);
    wrefresh(self->window);
}
Пример #22
0
static void handle(EVENT *e, int count)
{
	int old_mx, old_my, old_mb;
	int i;
	static int update_needed = 0;
	EVENT event;
	WIDGET *new_mfocus = NULL;

	old_mx = curr_mx;
	old_my = curr_my;
	old_mb = curr_mb;

	for(i=0;i<count;i++) {
		switch (e[i].type) {
			case EVENT_MOTION:
				set_pos(curr_mx + e[i].rel_x, curr_my + e[i].rel_y);
				break;

			case EVENT_ABSMOTION:
				set_pos(e[i].abs_x, e[i].abs_y);
				break;

			case EVENT_PRESS:
				press_cnt++;

				if (e[i].code == MTK_BTN_LEFT)  curr_mb = curr_mb | 0x01;
				if (e[i].code == MTK_BTN_RIGHT) curr_mb = curr_mb | 0x02;
				keytab[e[i].code] = 1;
				if (get_ascii(e[i].code)
				 || (e[i].code >= MTK_KEY_UP && e[i].code <= MTK_KEY_DELETE)) {
					curr_keystate = USERSTATE_KEY_PRESS;
					curr_keycode  = e[i].code;
					tick->add(key_repeat_delay, tick_handle_delay, (void *)curr_keycode);
				} else {
					curr_keystate = USERSTATE_KEY_IDLE;
					curr_keycode  = 0;
				}
				break;

			case EVENT_RELEASE:
				press_cnt--;

				if ((curr_state == USERSTATE_DRAG) && curr_motion_callback)
					curr_motion_callback(curr_selected, curr_mx - omx, curr_my - omy);

				if (e[i].code == MTK_BTN_LEFT)  curr_mb = curr_mb & 0x00fe;
				if (e[i].code == MTK_BTN_RIGHT) curr_mb = curr_mb & 0x00fd;
				keytab[e[i].code] = 0;
				curr_keystate = USERSTATE_KEY_IDLE;
				curr_keycode  = 0;
				break;
		}

		update_mfocus();

		if ((e[i].type == EVENT_PRESS) || (e[i].type == EVENT_RELEASE)) {
			WIDGET *win_kfocus = NULL;

			/* make clicked window the active one */
			if (curr_mfocus && key_sets_focus(e[i].code)) {
				WINDOW *w = (WINDOW *)curr_mfocus->gen->get_window(curr_mfocus);

				/* ignore clicks on the desktop (last window of window stack) */
				if (w->gen->get_next((WIDGET *)w))
					set_active_window(w, 1);
			}

			if (curr_window) {
				win_kfocus = curr_window->win->get_kfocus(curr_window);

				/* redefine keyboard focus */
				if (curr_mfocus && key_sets_focus(e[i].code) && curr_mfocus != win_kfocus)
					curr_mfocus->gen->focus(curr_mfocus);

				/* request new keyboard focus - just in case it denied the focus */
				win_kfocus = curr_window->win->get_kfocus(curr_window);
			}

			if ((e[i].type == EVENT_PRESS) && (press_cnt == 1)) {
				WIDGET *old_receiver = curr_receiver;

				/* send keyboard event to actually focused widget if set */
				if (win_kfocus && !key_sets_focus(e[i].code)) {
					if (win_kfocus) win_kfocus->gen->inc_ref(win_kfocus);
					curr_receiver = win_kfocus;
				} else {
					if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus);
					curr_receiver = curr_mfocus;
				}

				if (old_receiver)
					old_receiver->gen->dec_ref(old_receiver);
			}

			if (curr_receiver)
				curr_receiver->gen->handle_event(curr_receiver, &e[i], NULL);
		}
	}

	/*
	 * Hell! We got more key release events than press events
	 * This can happen when a key is pressed during the bootup
	 */
	if (press_cnt < 0) press_cnt = 0;

	tick->handle();

	switch (curr_state) {
		case USERSTATE_IDLE:

			/* if mouse position changed -> deliver motion event */
			if (old_mx != curr_mx || old_my != curr_my) {
				if (curr_mfocus) {
					event.type  = EVENT_MOTION;
					event.abs_x = curr_mx - curr_mfocus->gen->get_abs_x(curr_mfocus);
					event.abs_y = curr_my - curr_mfocus->gen->get_abs_y(curr_mfocus);
					event.rel_x = curr_mx - old_mx;
					event.rel_y = curr_my - old_my;
					curr_mfocus->gen->handle_event(curr_mfocus, &event, NULL);
				}
			}
			break;

		case USERSTATE_TOUCH:

			if (!curr_selected)
				break;

			if (curr_tick_callback)
				curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);

			if (press_cnt == 0) idle();

			new_mfocus = curr_scr->gen->find((WIDGET *)curr_scr, curr_mx, curr_my);
			if (new_mfocus != curr_mfocus) {
				if (new_mfocus == curr_selected) {
					if (curr_selected) {
						curr_selected->gen->set_state(curr_selected,1);
						curr_selected->gen->update(curr_selected);
					}
				} else {
					if (curr_selected) {
						curr_selected->gen->set_state(curr_selected,0);
						curr_selected->gen->update(curr_selected);
					}
				}
				if (curr_mfocus) curr_mfocus->gen->dec_ref(curr_mfocus);
				curr_mfocus = new_mfocus;
				if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus);
			}
			break;

		case USERSTATE_DRAG:

			if (press_cnt == 0) idle();

			if (curr_tick_callback) {
				curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);
			}
			if (old_mx != curr_mx || old_my != curr_my || update_needed) {
				update_needed = 1;
				if (curr_motion_callback && !redraw->is_queued((WIDGET *)curr_scr)) {
					update_needed = 0;
					curr_motion_callback(curr_selected, curr_mx - omx, curr_my - omy);
				}
			}
			break;

		case USERSTATE_GRAB:

			/* if mouse position changed -> deliver motion event */
			if (old_mx != curr_mx || old_my != curr_my) {
				s32 min_x = curr_selected->gen->get_abs_x(curr_selected);
				s32 min_y = curr_selected->gen->get_abs_y(curr_selected);
				s32 max_x = min_x + curr_selected->gen->get_w(curr_selected) - 1;
				s32 max_y = min_y + curr_selected->gen->get_h(curr_selected) - 1;

				if (curr_mx < min_x || curr_my < min_y ||
				    curr_mx > max_x || curr_my > max_y) {
					if (curr_mx < min_x) curr_mx = min_x;
					if (curr_my < min_y) curr_my = min_y;
					if (curr_mx > max_x) curr_mx = max_x;
					if (curr_my > max_y) curr_my = max_y;
					set_pos(curr_mx, curr_my);
				}

				event.type  = EVENT_MOTION;
				event.abs_x = curr_mx - min_x;
				event.abs_y = curr_my - min_y;
				event.rel_x = curr_mx - old_mx;
				event.rel_y = curr_my - old_my;
				curr_selected->gen->handle_event(curr_selected, &event, NULL);
			}
			if (curr_tick_callback) {
				curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);
			}
			break;
	}
	scrdrv->set_mouse_pos(curr_mx, curr_my);
}
Пример #23
0
static void handle(void)
{
  static long    old_mx, old_my, old_mb;
  static long    update_needed = 0;
  static EVENT   event;

  WIDGET *new_mfocus = NULL;

  old_mx = curr_mx;
  old_my = curr_my;
  old_mb = curr_mb;

  while (input->get_event(&event))
    {
      switch (event.type)
	{
	case EV_REL:
	  if (event.code == REL_X)
	    set_pos(curr_mx + event.value, curr_my);
	  else if (event.code == REL_Y)
	    set_pos(curr_mx, curr_my + event.value);
	  break;

	case EV_ABS:
	  if (event.code == ABS_X)
	    set_pos(event.value, curr_my);
	  else if (event.code == ABS_Y)
	    set_pos(curr_mx, event.value);
	  break;

	case EV_KEY:
	  if (event.value == 1)
	    {
	      press_cnt++;

	      if (event.code == BTN_LEFT)  curr_mb = curr_mb | 0x01;
	      if (event.code == BTN_RIGHT) curr_mb = curr_mb | 0x02;
	      keytab[event.code] = 1;
	      if (get_ascii(event.code)
		  || (event.code >= KEY_UP && event.code <= KEY_DELETE))
		{
		  curr_keystate = USERSTATE_KEY_PRESS;
		  curr_keycode  = event.code;
		  tick->add(key_repeat_delay, tick_handle_delay, (void *)curr_keycode);
		}
	      else
		{
		  curr_keystate = USERSTATE_KEY_IDLE;
		  curr_keycode  = 0;
		}
	    }
	  else if (event.value == 0)
	    {
	      press_cnt--;

	      if (event.code == BTN_LEFT)  curr_mb = curr_mb & 0x00fe;
	      if (event.code == BTN_RIGHT) curr_mb = curr_mb & 0x00fd;
	      keytab[event.code] = 0;
	      curr_keystate = USERSTATE_KEY_IDLE;
	      curr_keycode  = 0;
	    }
	  break;
	}

      update_mfocus();

      if (event.type == EV_KEY)
	{

	  WIDGET *win_kfocus = NULL;

	  /* make clicked window the active one */
	  if (curr_mfocus && key_sets_focus(event.code))
	    {
	      WINDOW *w = (WINDOW *)curr_mfocus->gen->get_window(curr_mfocus);
	      set_active_window(w, 1);
	    }

	  if (curr_window)
	    {
	      win_kfocus = curr_window->win->get_kfocus(curr_window);

	      /* redefine keyboard focus */
	      if (curr_mfocus && key_sets_focus(event.code) && curr_mfocus != win_kfocus)
		curr_mfocus->gen->focus(curr_mfocus);

	      /* request new keyboard focus - just in case it denied the focus */
	      win_kfocus = curr_window->win->get_kfocus(curr_window);
	    }

	  if ((event.value == 1) && (press_cnt == 1))
	    {

	      WIDGET *old_receiver = curr_receiver;

	      /* send keyboard event to actually focused widget if set */
	      if (win_kfocus && !key_sets_focus(event.code))
		{
		  if (win_kfocus) win_kfocus->gen->inc_ref(win_kfocus);
		  curr_receiver = win_kfocus;
		}
	      else
		{
		  if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus);
		  curr_receiver = curr_mfocus;
		}

	      if (old_receiver)
		old_receiver->gen->dec_ref(old_receiver);
	    }

	  if (curr_receiver)
	    curr_receiver->gen->handle_event(curr_receiver, &event, NULL);
      }
  }

  /*
   * Hell! We got more key release events than press events
   * This can happen when a key is pressed during the bootup
   */
  if (press_cnt < 0) press_cnt = 0;

  tick->handle();

  switch (curr_state)
    {

    case USERSTATE_IDLE:

      /* if mouse position changed -> deliver motion event */
      if (old_mx != curr_mx && curr_mfocus)
	{
	  event.type  = EV_ABS;
	  event.code  = ABS_X;
	  event.value  = curr_mx - curr_mfocus->gen->get_abs_x(curr_mfocus);
	  curr_mfocus->gen->handle_event(curr_mfocus, &event, NULL);
	}
      if (old_my != curr_my && curr_mfocus)
	{
	  event.type  = EV_ABS;
	  event.code  = ABS_Y;
	  event.value  = curr_my - curr_mfocus->gen->get_abs_y(curr_mfocus);
	  curr_mfocus->gen->handle_event(curr_mfocus, &event, NULL);
	}
      break;

    case USERSTATE_TOUCH:

      if (curr_tick_callback)
	curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);

      if (press_cnt == 0)
	idle();

      new_mfocus = curr_scr->gen->find((WIDGET *)curr_scr, curr_mx, curr_my);
      if (new_mfocus != curr_mfocus)
	{
	  if (new_mfocus == curr_selected)
	    {
	      curr_selected->gen->set_state(curr_selected,1);
	      curr_selected->gen->update(curr_selected);
	    }
	  else
	    {
	      curr_selected->gen->set_state(curr_selected,0);
	      curr_selected->gen->update(curr_selected);
	    }
	  if (curr_mfocus)
	    curr_mfocus->gen->dec_ref(curr_mfocus);

	  curr_mfocus = new_mfocus;

	  if (curr_mfocus)
	    curr_mfocus->gen->inc_ref(curr_mfocus);
	}
      break;

    case USERSTATE_DRAG:

      if (press_cnt == 0)
	idle();

      if (curr_tick_callback)
	{
	  curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);
	}
      if (old_mx != curr_mx || old_my != curr_my || update_needed)
	{
	  update_needed = 1;
	  if (curr_motion_callback && !redraw->is_queued((WIDGET *)curr_scr))
	    {
	      update_needed = 0;
	      curr_motion_callback(curr_selected, curr_mx - omx, curr_my - omy);
	    }
	}
      break;

    case USERSTATE_GRAB:
#if 0
      /* if mouse position changed -> deliver motion event */
      if (old_mx != curr_mx || old_my != curr_my)
	{
	  s32 min_x = curr_selected->gen->get_abs_x(curr_selected);
	  s32 min_y = curr_selected->gen->get_abs_y(curr_selected);
	  s32 max_x = min_x + curr_selected->gen->get_w(curr_selected) - 1;
	  s32 max_y = min_y + curr_selected->gen->get_h(curr_selected) - 1;

	  if (curr_mx < min_x || curr_my < min_y ||
	      curr_mx > max_x || curr_my > max_y)
	    {
	      if (curr_mx < min_x) curr_mx = min_x;
	      if (curr_my < min_y) curr_my = min_y;
	      if (curr_mx > max_x) curr_mx = max_x;
	      if (curr_my > max_y) curr_my = max_y;
	      set_pos(curr_mx, curr_my);
	    }

	  event.type  = EVENT_MOTION;
	  event.abs_x = curr_mx - min_x;
	  event.abs_y = curr_my - min_y;
	  event.rel_x = curr_mx - old_mx;
	  event.rel_y = curr_my - old_my;
	  curr_selected->gen->handle_event(curr_selected, &event, NULL);
	}
      if (curr_tick_callback)
	{
	  curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);
	}
#endif
      break;
    }
  scrdrv->set_mouse_pos(curr_mx, curr_my);
}
Пример #24
0
static void friendlist_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
{

    if (self->help->active) {
        help_onKey(self, key);
        return;
    }

    if (key == 'h') {
        help_init_menu(self);
        return;
    }

    if (!blocklist_view && !Friends.num_friends && (key != KEY_RIGHT && key != KEY_LEFT))
        return;

    if (blocklist_view && !Blocked.num_blocked && (key != KEY_RIGHT && key != KEY_LEFT))
        return;

    int f = 0;

    if (blocklist_view == 1 && Blocked.num_blocked)
        f = Blocked.index[Blocked.num_selected];
    else if (Friends.num_friends)
        f = Friends.index[Friends.num_selected];

    /* lock screen and force decision on deletion popup */
    if (PendingDelete.active) {
        if (key == 'y' || key == 'n')
            del_friend_deactivate(self, m, key);

        return;
    }

    if (key == ltr)
        return;

    switch (key) {
        case '\n':
            if (blocklist_view)
                break;

            /* Jump to chat window if already open */
            if (Friends.list[f].chatwin != -1) {
                set_active_window(Friends.list[f].chatwin);
            } else if (get_num_active_windows() < MAX_WINDOWS_NUM) {
                Friends.list[f].chatwin = add_window(m, new_chat(m, Friends.list[f].num));
                set_active_window(Friends.list[f].chatwin);
            } else {
                const char *msg = "* Warning: Too many windows are open.";
                line_info_add(prompt, NULL, NULL, NULL, SYS_MSG, 0, RED, msg);
                sound_notify(prompt, notif_error, NT_WNDALERT_1, NULL);
            }

            break;

        case KEY_DC:
            del_friend_activate(self, m, f);
            break;

        case 'b':
            if (!blocklist_view)
                block_friend(m, f);
            else
                unblock_friend(m, f);
            break;

        case KEY_RIGHT:
        case KEY_LEFT:
            blocklist_view ^= 1;
            break;

        default:
            if (blocklist_view == 0)
                select_friend(self, key, &Friends.num_selected, Friends.num_friends);
            else
                select_friend(self, key, &Blocked.num_selected, Blocked.num_blocked);
            break;
    }
}
Пример #25
0
int XNextEvent(Display *display, XEvent *outEvent) {
  // Code to pull the real function handle from X11 library.
  void *handle = NULL;

  //This will turn the function proto into a function pointer declaration
  int (*real_func)(Display *display, XEvent *outEvent) = NULL;
  handle = get_xlib_handle();

  if (handle == NULL) {
    return -1;
  }

  // The real event from XNextEvent
  XEvent realEvent;

  // Find the real function.
  real_func = dlsym(handle, "XNextEvent");
  // Invoke the real function.
  int rf_ret = real_func(display, &realEvent);

  OPEN_LOGGING_FILE;

  if (g_library_inited == FALSE) {
    LOG("Library initialized.\n");
    g_library_inited = TRUE;
    init_cached_xquerytree();
    init_focus_keep_struct(&g_focus_status);
  }


  // This display object will be used to inquire X server
  // about inferior and parent windows.
  Display* dpy = display;
  //assert(dpy != NULL);

  print_event_to_log(dpy, &realEvent);

  // Is the event on a window other than the active one?
  // If so, update gActiveWindow on two cases:
  // 1. It's the first window known to the module.
  // 2. It's the second window known to the module. The second
  // window is the actual browser window (the first one is just a
  // set-up one).
  //
  if ((get_active_window(&g_focus_status) == 0) && (is_focus_in(&realEvent))) {
    set_active_window(&g_focus_status, &realEvent);
  } else {
    identify_switch_situation(&g_focus_status);
  }

  if (is_reparent_notify(&realEvent)) {
    identify_new_window_situation(&g_focus_status, &realEvent);
  }

  if (is_destroy_notify(&realEvent)) {
    identify_active_destroyed(&g_focus_status, &realEvent);
  }

  if ((g_focus_status.during_switch == TRUE) ||
      (get_active_window(&g_focus_status) == 0)) {
      LOG("During switch: %d Active win: %#lx during close: %d\n",
          g_focus_status.during_switch, get_active_window(&g_focus_status),
          g_focus_status.during_close);
    *outEvent = realEvent;
  } else if (should_discard_focus_out_event(&g_focus_status, dpy, &realEvent)) {
    // Fake an event!
    fake_keymap_notify_event(outEvent, &realEvent);
    LOG("Fake event for focus out.\n");
  }  else if (should_discard_focus_in_event(&g_focus_status, dpy, &realEvent)) {
    fake_keymap_notify_event(outEvent, &realEvent);
    LOG("Fake event for focus in.\n");
  } else {
    *outEvent = realEvent;
  }

  steal_focus_back_if_needed(&g_focus_status, dpy);

  dlclose(handle);
  CLOSE_LOGGING_FILE;
  return rf_ret;
}