/* * choose a desktop name */ char *choose_title(char *display) { static char title[(MAXN+10)]; memset(title, 0, MAXN+10); strcpy(title, "x11vnc"); if (display == NULL) { display = getenv("DISPLAY"); } if (display == NULL) { return title; } title[0] = '\0'; if (display[0] == ':') { char *th = this_host(); if (th != NULL) { strncpy(title, th, MAXN - strlen(title)); } } strncat(title, display, MAXN - strlen(title)); if (subwin && dpy && valid_window(subwin, NULL, 0)) { char *name = NULL; if (XFetchName(dpy, subwin, &name)) { if (name) { strncat(title, " ", MAXN - strlen(title)); strncat(title, name, MAXN - strlen(title)); free(name); } } } return title; }
static int handle_subwin_resize(char *msg) { int new_x, new_y; int i, check = 10, ms = 250; /* 2.5 secs total... */ if (msg) {} /* unused vars warning: */ if (! subwin) { return 0; /* hmmm... */ } if (! valid_window(subwin, NULL, 0)) { rfbLogEnable(1); rfbLog("subwin 0x%lx went away!\n", subwin); X_UNLOCK; clean_up_exit(1); } if (! get_window_size(subwin, &new_x, &new_y)) { rfbLogEnable(1); rfbLog("could not get size of subwin 0x%lx\n", subwin); X_UNLOCK; clean_up_exit(1); } if (wdpy_x == new_x && wdpy_y == new_y) { /* no change */ return 0; } /* window may still be changing (e.g. drag resize) */ for (i=0; i < check; i++) { int newer_x, newer_y; usleep(ms * 1000); if (! get_window_size(subwin, &newer_x, &newer_y)) { rfbLogEnable(1); rfbLog("could not get size of subwin 0x%lx\n", subwin); clean_up_exit(1); } if (new_x == newer_x && new_y == newer_y) { /* go for it... */ break; } else { rfbLog("subwin 0x%lx still changing size...\n", subwin); new_x = newer_x; new_y = newer_y; } } rfbLog("subwin 0x%lx new size: x: %d -> %d, y: %d -> %d\n", subwin, wdpy_x, new_x, wdpy_y, new_y); rfbLog("calling handle_xrandr_change() for resizing\n"); X_UNLOCK; handle_xrandr_change(new_x, new_y); return 1; }
int sel_yank(int reg) { REGIONSHAPE save_shape; WINDOW *save_wp; BUFFER *save_bp = curbp; int code = FALSE; TRACE((T_CALLED "sel_yank(%d)\n", reg)); if (valid_window(save_wp = push_fake_win(selbufp))) { /* * We're not guaranteed that curbp and selbufp are the same. */ save_shape = regionshape; curbp = selbufp; ukb = (short) reg; kregflag = 0; haveregion = &selregion.ar_region; regionshape = selregion.ar_shape; yankregion(); haveregion = NULL; #ifdef GMDCBRD_ECHO if (global_g_val(GMDCBRD_ECHO)) cbrdcpy_unnamed(FALSE, FALSE); #endif pop_fake_win(save_wp, save_bp); regionshape = save_shape; show_selection_position(TRUE); /* put cursor back on screen...is there a cheaper way to do this? */ (void) update(FALSE); code = TRUE; } returnCode(code); }
/* * On button press, we get an explicit number (1,2,3), and on release we don't * really know which button, but assume it is the last-pressed button. */ int on_mouse_click(int button, int y, int x) { static int first_x, first_y, pending; WINDOW *this_wp, *that_wp; int status; if (button > 0) { if (valid_window(this_wp = row2window(y)) && (y != mode_row(this_wp))) { /* * If we get a click on the "<" marking the left side * of a shifted window, force the screen right. This * makes it more consistent if there's a tab. */ if (w_val(this_wp, WVAL_SIDEWAYS) && x == 0) { mvleftwind(FALSE, 1); } if (!doingsweep) { if (button == BTN_EXTEND) { first_x = offs2col(this_wp, this_wp->w_dot.l, this_wp->w_dot.o); first_y = line_no(this_wp->w_bufp, this_wp->w_dot.l) - line_no(this_wp->w_bufp, this_wp->w_line.l); } else { first_x = x; first_y = y; } } status = setcursor(y, x); /* * Check for button1-down while we're in multimotion * sweep, so we can suppress highlighting extension. */ if (button != BTN_EXTEND && status == TRUE && doingsweep) { status = SORTOFTRUE; if (button == BTN_BEGIN) { first_x = x; first_y = y; } } } else { /* pressed button on modeline */ status = SORTOFTRUE; first_x = x; first_y = y; } pending = button; } else if (pending) { button = pending; pending = FALSE; this_wp = row2window(y); that_wp = row2window(first_y); if (this_wp == 0 || that_wp == 0 || reading_msg_line) { TRACE(("MOUSE cannot move msg-line\n")); status = FALSE; } else if (insertmode && (this_wp != curwp || that_wp != curwp)) { TRACE(("MOUSE cannot move from window while inserting\n")); kbd_alarm(); status = ABORT; } else if (first_y == mode_row(that_wp)) { /* drag modeline? */ if (first_y == y) { sel_release(); status = SEL_RELEASE; } else { WINDOW *save_wp = curwp; TRACE(("MOUSE dragging modeline\n")); set_curwp(that_wp); status = shrinkwind(FALSE, first_y - y); set_curwp(save_wp); } } else if (y != first_y || x != first_x) { /* drag selection */ if (button == BTN_PASTE) { (void) setcursor(y, x); status = paste_selection(); } else if (doingsweep) { switch (button) { case BTN_BEGIN: (void) release_selection(TRUE); status = setcursor(first_y, first_x); if (status == TRUE) { MK = DOT; status = SEL_BEGIN; TRACE(("MOUSE setting SEL_BEGIN MK %d.%d\n", line_no(curbp, MK.l), MK.o)); } break; default: (void) setcursor(y, x); status = SEL_EXTEND; TRACE(("MOUSE setting SEL_EXTEND DOT %d.%d MK %d.%d\n", line_no(curbp, MK.l), MK.o, line_no(curbp, DOT.l), DOT.o)); break; } } else { TRACE(("MOUSE begin multimotion on button%d-up\n", button)); if (button == BTN_EXTEND) { (void) setcursor(y, x); y = first_y; x = first_x; } do_sweep(SORTOFTRUE); (void) sel_begin(); (void) sel_setshape(rgn_EXACT); (void) setcursor(y, x); status = multimotion(TRUE, 1); TRACE(("MOUSE end multimotion after button%d-up\n", button)); if (status == SEL_PASTE) status = paste_selection(); } } else { /* position the cursor */ TRACE(("MOUSE button %d position cursor\n", button)); (void) setcursor(y, x); switch (button) { case BTN_BEGIN: status = SEL_FINISH; break; case BTN_PASTE: status = paste_selection(); break; default: status = release_selection(TRUE); break; } } } else { TRACE(("MOUSE ignored (illegal state)\n")); status = FALSE; } if (status == TRUE || status >= SORTOFTRUE) (void) update(TRUE); TRACE(("MOUSE status:%d\n", status)); return status; }