/** * Updates current->cols with the current window size (width) */ static int getWindowSize(struct current *current) { struct winsize ws; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0 && ws.ws_col != 0) { current->cols = ws.ws_col; return 0; } /* Failed to query the window size. Perhaps we are on a serial terminal. * Try to query the width by sending the cursor as far to the right * and reading back the cursor position. * Note that this is only done once per call to linenoise rather than * every time the line is refreshed for efficiency reasons. * * In more detail, we: * (a) request current cursor position, * (b) move cursor far right, * (c) request cursor position again, * (d) at last move back to the old position. * This gives us the width without messing with the externally * visible cursor position. */ if (current->cols == 0) { int here; current->cols = 80; /* (a) */ if (queryCursor (current->fd, &here)) { /* (b) */ fd_printf(current->fd, "\x1b[999C"); /* (c). Note: If (a) succeeded, then (c) should as well. * For paranoia we still check and have a fallback action * for (d) in case of failure.. */ if (!queryCursor (current->fd, ¤t->cols)) { /* (d') Unable to get accurate position data, reset * the cursor to the far left. While this may not * restore the exact original position it should not * be too bad. */ fd_printf(current->fd, "\r"); } else { /* (d) Reset the cursor back to the original location. */ if (current->cols > here) { fd_printf(current->fd, "\x1b[%dD", current->cols - here); } } } /* 1st query failed, doing nothing => default 80 */ } return 0; }
void Component::mouseMoved(MouseEventDetails* const e) { if(getParentWindow() != NULL && getParentWindow()->getParentDrawingSurface()!=NULL&&getParentWindow()->getParentDrawingSurface()->getEventProducer() != NULL) { getParentWindow()->getParentDrawingSurface()->getEventProducer()->setCursorType(queryCursor(e->getLocation())); } produceMouseMoved(e); }