Exemple #1
0
static void
GrMoveWindowWrapper(void *r)
{
	nxMoveWindowReq *req = r;

	GrMoveWindow(req->windowid, req->x, req->y);
}
Exemple #2
0
/*
 * Handle mouse position events
 */
static void
do_mouse(GR_EVENT_MOUSE *ep)
{
#ifdef SHOW_WINDOW_MOTION
	GR_WINDOW_INFO winfo;

	if(!in_motion) return;

	in_motion->x = ep->rootx - move_xoff - 1;
	in_motion->y = ep->rooty - move_yoff - 1;
	GrMoveWindow(in_motion->fid, in_motion->x + 1, in_motion->y + 1);
	GrGetWindowInfo(in_motion->wid, &winfo);
	GrMoveWindow(in_motion->wid, in_motion->x + winfo.bordersize - 1,
			in_motion->y + 2 * winfo.bordersize + DEC_HEIGHT - 1);
#endif
}
Exemple #3
0
void
mvpw_move(mvp_widget_t *widget, int x, int y)
{
	int i, size, count;
	mvp_widget_t **list;

	if ((list=malloc(sizeof(*list)*128)) == NULL)
		return;

	size = 128;
	count = 0;
	if ((list=attach_list(widget, list, &size, &count)) == NULL)
		return;

	for (i=0; i<count; i++) {
		list[i]->x += x;
		list[i]->y += y;
		GrMoveWindow(list[i]->wid, list[i]->x, list[i]->y);
#if 1
		mvpw_expose(list[i]);
#endif
	}

	if (count > 0)
		mvpw_expose(root);

	free(list);
}
Exemple #4
0
void topbar_mousemoved(win *window, GR_EVENT_MOUSE *event)
{
	struct position *pos;
	GR_WM_PROPERTIES props;

	Dprintf("topbar_mousemoved window %d\n", window->wid);

	if(!window->active)
		return;

	pos = (struct position *) window->data;

	/* turn off background erase draw while moving*/
	GrGetWMProperties(window->pid, &props);
	if (props.title)
		free(props.title);
	props.flags = GR_WM_FLAGS_PROPS;
	props.props |= GR_WM_PROPS_NOBACKGROUND;
	GrSetWMProperties(window->pid, &props);

	GrMoveWindow(window->pid, event->rootx - pos->x,
			event->rooty - pos->y);

	props.props &= ~GR_WM_PROPS_NOBACKGROUND;
	GrSetWMProperties(window->pid, &props);
}
Exemple #5
0
static void
do_buttonup(GR_EVENT_BUTTON *ep)
{
#ifdef SHOW_WINDOW_MOTION
	in_motion = NULL;
#else
	mwin *	mwp;
	GR_WINDOW_INFO winfo;

	if ((mwp = IsDecoration(ep->wid)) != NULL) {
		if (mwp == in_motion) {
			mwp->x = ep->rootx - 1 - move_xoff;
			mwp->y = ep->rooty - 1 - move_yoff;
			GrMoveWindow(mwp->fid, mwp->x + 1, mwp->y + 1);
			GrGetWindowInfo(mwp->wid, &winfo);
			GrMoveWindow(mwp->wid, mwp->x + winfo.bordersize,
				mwp->y + 2 * winfo.bordersize + DEC_HEIGHT);
			in_motion = NULL;
		}
	}
#endif
}
Exemple #6
0
void leftbar_mousemoved(win *window, GR_EVENT_MOUSE *event)
{
	GR_COORD newx;
	GR_SIZE newwidth;
	struct pos_size *pos;

	Dprintf("leftbar_mousemoved window %d\n", window->wid);

	if(!window->active)
		return;

	pos = (struct pos_size *) window->data;
	newx = event->rootx - pos->xoff;
	newwidth = pos->width + pos->xorig - event->rootx - pos->xoff;

	GrMoveWindow(window->pid, newx, pos->yorig);
	GrResizeWindow(window->pid, newwidth, pos->height);
}
Exemple #7
0
void position_event(GR_EVENT_MOUSE *ev, nxeyes_state *state)
{
	GR_COORD newx, newy;

	state->mouse_moved = 1;
	state->mousex = ev->rootx;
	state->mousey = ev->rooty;

	if(ev->wid == GR_ROOT_WINDOW_ID) return;

	if(!state->button_down) return;

	newx = ev->rootx - state->x;
	newy = ev->rooty - state->y;

	if(newx != state->oldx || newy != state->oldy) {
		GrMoveWindow(ev->wid, newx, newy);
		state->oldx = newx;
		state->oldy = newy;
	}
}
Exemple #8
0
void wm_container_mousemoved(win *window, GR_EVENT_MOUSE *event)
{
	struct pos_size *pos;
	GR_GC_ID gc;
	GR_RECT r;
	GR_WINDOW_INFO info;

	Dprintf("wm_container_mousemoved window %d\n", window->wid);

	GrGetWindowInfo(window->wid, &info);

	if(window->sizing) {
	  struct pos_size * pos = (struct pos_size*)window->data;

	  /* erase old rectangle */
	  gc = GrNewGC();
	  GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	  GrRect(GR_ROOT_WINDOW_ID, gc, info.x, info.y, pos->width, pos->height);

	  /* draw new one */
	  GrRect(GR_ROOT_WINDOW_ID,gc,info.x, info.y, event->rootx - info.x, event->rooty - info.y);
	  GrDestroyGC(gc);

	  /* save this new rectangle's width, height */
	  /* I know, this shouldn't be stored in x/y, but... */
	  pos->width = event->rootx - info.x;
	  pos->height = event->rooty - info.y;
	  return;
	}

#if !NO_CORNER_RESIZE
	/* check corner resize cursor on/off*/
	r.x = info.width - 5;
	r.y = info.height - 5;
	r.width = 5;
	r.height = 5;
	if (PtInRect(&r,event->x, event->y))
		set_resize_cursor(window->wid);
	else
		GrSetWindowCursor(window->wid, 0);
#endif

	if(!window->active)
		return;

	pos = (struct pos_size *)window->data;
#if OUTLINE_MOVE
	gc = GrNewGC();
	GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	GrRect(GR_ROOT_WINDOW_ID,gc,pos->xorig, pos->yorig, pos->width, pos->height);
	GrRect(GR_ROOT_WINDOW_ID,gc,event->rootx - pos->xoff, event->rooty - pos->yoff,
	       pos->width, pos->height);

	pos->xorig = event->rootx - pos->xoff;
	pos->yorig = event->rooty - pos->yoff;
	
	GrDestroyGC(gc);
#else	
	GrMoveWindow(window->wid, event->rootx - pos->xoff, event->rooty - pos->yoff);
#endif
}
Exemple #9
0
void wm_container_buttonup(win *window, GR_EVENT_BUTTON *event)
{
	GR_RECT		r;
	GR_COORD	cxborder = 0, cyborder = 0;
	GR_WINDOW_INFO	info;

	Dprintf("wm_container_buttonup window %d\n", window->wid);

	GrGetWindowInfo(window->wid, &info);

	/* Check for close box press*/
	if ((info.props & (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) ==
	    (GR_WM_PROPS_CAPTION|GR_WM_PROPS_CLOSEBOX)) {

		/* calc border sizes*/
		if (info.props & GR_WM_PROPS_BORDER) {
			cxborder = 1;
			cyborder = 1;
		}
		if (info.props & GR_WM_PROPS_APPFRAME) {
			cxborder = CXBORDER;
			cyborder = CYBORDER;
		}

		/* Get close box rect*/
		r.x = info.width - CXCLOSEBOX - cxborder - 2;
		r.y = cyborder + 2;
		r.width = CXCLOSEBOX;
		r.height = CYCLOSEBOX;

		/* Check mouseup in close box*/
		if (PtInRect(&r, event->x, event->y)) {
			if(window->close == GR_TRUE) {
				/*
				 * This sends a CLOSE_REQ event to the window.
				 * NXLIB clients catch this and convert it
				 * to an X11 ClientMessage with a WM_DELETE_WINDOW
				 * atom, causing the window to close.
				 */
				GrCloseWindow(window->clientid);
        		window->close = GR_FALSE;
        		return;
      		}
		}
	}
	window->close = GR_FALSE;

	if(window->active) {
#if OUTLINE_MOVE
	  struct pos_size * pos = (struct pos_size *)window->data;
	  GR_GC_ID gc = GrNewGC();

	  GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	  GrRect(GR_ROOT_WINDOW_ID, gc, pos->xorig, pos->yorig, pos->width, pos->height);
	  GrMoveWindow(window->wid, pos->xorig, pos->yorig);
	  GrDestroyGC(gc);
#endif
	  free(window->data);
	  window->active = GR_FALSE;
	  window->data = 0;
	}
	
	if(window->sizing) {
	  struct pos_size * pos = (struct pos_size *)window->data;
	  GR_GC_ID gc = GrNewGC();
	  GR_WINDOW_INFO info;
	  GR_SIZE w, h;

	  GrGetWindowInfo(window->wid, &info);
	  GrSetGCMode(gc, GR_MODE_XOR|GR_MODE_EXCLUDECHILDREN);
	  GrRect(GR_ROOT_WINDOW_ID, gc, info.x, info.y, pos->width, pos->height);
	  GrDestroyGC(gc);

	  w = info.width + (event->x - pos->xorig);
	  h = info.height + (event->y - pos->yorig);
	  GrResizeWindow(window->wid, w, h);
	  GrResizeWindow(window->clientid, w - pos->xoff, h - pos->yoff);

	  free(window->data);
	  window->sizing = GR_FALSE;
	  window->data = 0;
	}
}
Exemple #10
0
int
mvpw_attach(mvp_widget_t *w1, mvp_widget_t *w2, int direction)
{
	int ret = 0, i, size, count;
	GR_COORD x = 0, y = 0;
	mvp_widget_t **list, **l;

	switch (direction) {
	case MVPW_DIR_UP:
	case MVPW_DIR_DOWN:
	case MVPW_DIR_LEFT:
	case MVPW_DIR_RIGHT:
		break;
	default:
		return -1;
		break;
	}

	if ((list=malloc(sizeof(*list)*128)) == NULL)
		return -1;

	size = 128;
	count = 0;
	l = list;
	if ((list=attach_list(w2, list, &size, &count)) == NULL) {
		free(l);
		return -1;
	}

	for (i=0; i<count; i++)
		if (list[i] == w1) {
			free(list);
			return -1;
		}

	switch (direction) {
	case MVPW_DIR_UP:
		x = w1->x;
		y = w1->y - w2->height;
		break;
	case MVPW_DIR_DOWN:
		x = w1->x;
		y = w1->y + w1->height;
		break;
	case MVPW_DIR_LEFT:
		x = w1->x - w1->width;
		y = w1->y;
		break;
	case MVPW_DIR_RIGHT:
		x = w1->x + w1->width;
		y = w1->y;
		break;
	}

	x = x - w2->x;
	y = y - w2->y;
	for (i=0; i<count; i++) {
		list[i]->x += x;
		list[i]->y += y;
		GrMoveWindow(list[i]->wid, list[i]->x, list[i]->y);
	}

	w1->attach[direction] = w2;
	switch (direction) {
	case MVPW_DIR_UP:
		w2->attach[MVPW_DIR_DOWN] = w1;
		break;
	case MVPW_DIR_DOWN:
		w2->attach[MVPW_DIR_UP] = w1;
		break;
	case MVPW_DIR_LEFT:
		w2->attach[MVPW_DIR_RIGHT] = w1;
		break;
	case MVPW_DIR_RIGHT:
		w2->attach[MVPW_DIR_LEFT] = w1;
		break;
	}

	free(list);

	return ret;
}
Exemple #11
0
int
main(int ac,char **av)
{
	GR_WINDOW_ID 	w, w2;
	GR_GC_ID	gc;
	GR_EVENT 	event;
	GR_WM_PROPERTIES props;

	if (GrOpen() < 0) {
		printf("Can't open graphics\n");
		exit(1);
	}

	/* pass errors through main loop*/
	GrSetErrorHandler(NULL);

#define WIDTH	320
#define HEIGHT	240
	w = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, WIDTH, HEIGHT,
		0, GREEN, BLACK);

	w2 = GrNewWindow(w, 20, 20, 40, 40, 0, WHITE, BLACK);

	props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE;
	props.props = GR_WM_PROPS_NOBACKGROUND;
	props.title = "Nano-X Demo2";
	GrSetWMProperties(w, &props);

	gc = GrNewGC();

	GrSelectEvents(w, GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_CLOSE_REQ
		| GR_EVENT_MASK_BUTTON_DOWN
		| GR_EVENT_MASK_KEY_DOWN | GR_EVENT_MASK_KEY_UP);
	GrMapWindow(w);
	GrSetFocus(w);
	/* serious bug here: when wm running, w2 is mapped anyway!!*/
	/*GrMapWindow(w2);*/

	for (;;) {
		/*GR_EVENT_KEYSTROKE *kev;*/

		GrGetNextEvent(&event);
		switch (event.type) {
		case GR_EVENT_TYPE_EXPOSURE:
			GrSetGCForeground(gc,GrGetSysColor(GR_COLOR_APPWINDOW));
			GrFillRect(w, gc, event.exposure.x, event.exposure.y,
				event.exposure.width, event.exposure.height);
			GrSetGCForeground(gc, GrGetSysColor(GR_COLOR_APPTEXT));
			GrSetGCUseBackground(gc, GR_FALSE);
			GrText(w, gc, 10, 30, "Hello World", -1, GR_TFASCII);
GrRect(w, gc, 5, 5, 300, 60);
			break;
		case GR_EVENT_TYPE_CLOSE_REQ:
			GrClose();
			exit(0);
			break;
		case GR_EVENT_TYPE_ERROR:
			printf("\7demo2: Error (%s) ", event.error.name);
			printf(nxErrorStrings[event.error.code],event.error.id);
			break;
#if 0
		case GR_EVENT_TYPE_BUTTON_DOWN:
			/* test server error on bad syscall*/
			GrMapWindow(w2);
			GrMoveWindow(GR_ROOT_WINDOW_ID, 0, 0);
			{ GR_SCREEN_INFO sinfo; GrGetScreenInfo(&sinfo); }
			break;
#endif
#if 0
		case GR_EVENT_TYPE_KEY_DOWN:
			kev = (GR_EVENT_KEYSTROKE *)&event;
			printf("DOWN %d (%04x) %04x\n",
				kev->ch, kev->ch, kev->modifiers);
			break;
		case GR_EVENT_TYPE_KEY_UP:
			kev = (GR_EVENT_KEYSTROKE *)&event;
			printf("UP %d (%04x) %04x\n",
				kev->ch, kev->ch, kev->modifiers);
			break;
#endif
		}
	}

	GrClose();
	return 0;
}
Exemple #12
0
/*
 * Demo to test child window movement and redrawing
 */
int 
main(int ac,char **av)
{
  GR_COORD      offset_x = 0, offset_y = 0;
  GR_WINDOW_ID 	window1, subwindow1, subsubwin1;
  GR_WINDOW_ID 	window2, subwindow2;
  /*GR_WINDOW_ID	subsubwin2;*/
  GR_EVENT 	event;

  fprintf(stderr,"This is a demo program.\n");
  fprintf(stderr,"Left-button drags window\n");
  fprintf(stderr,"Right-button raises window\n");
  
  GrOpen();
  window1 = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 20, 100, 60, 4, BLACK, BLUE);
  subwindow1 = GrNewWindow(window1, 5, 5, 90, 50, 4, WHITE, RED);
  subsubwin1 = GrNewWindow(subwindow1, 10, 10, 10, 10, 2, GREEN, BLUE);

  window2 = GrNewWindow(GR_ROOT_WINDOW_ID, 20, 100, 100, 60, 4, BLACK, BLUE);
  subwindow2 = GrNewWindow(window2, 5, 5, 90, 50, 4, WHITE, RED);
/*    subsubwin2 = GrNewWindow(subwindow2, 10, 10, 10, 10, 2, GREEN, BLUE); */

  GrSelectEvents(window1, 
  		 GR_EVENT_MASK_EXPOSURE |
		 GR_EVENT_MASK_BUTTON_DOWN |
		 GR_EVENT_MASK_BUTTON_UP |
		 GR_EVENT_MASK_MOUSE_ENTER |
		 GR_EVENT_MASK_MOUSE_EXIT |
		 GR_EVENT_MASK_MOUSE_MOTION |
		 GR_EVENT_MASK_CLOSE_REQ);

  GrSelectEvents(window2, 
  		 GR_EVENT_MASK_EXPOSURE |
		 GR_EVENT_MASK_BUTTON_DOWN |
		 GR_EVENT_MASK_BUTTON_UP |
		 GR_EVENT_MASK_MOUSE_ENTER |
		 GR_EVENT_MASK_MOUSE_EXIT |
		 GR_EVENT_MASK_MOUSE_MOTION |
		 GR_EVENT_MASK_CLOSE_REQ);

  GrSelectEvents(subsubwin1, 
		 GR_EVENT_MASK_BUTTON_DOWN |
		 0);

  GrMapWindow(subsubwin1);
  GrMapWindow(subwindow1);
  GrMapWindow(window1);

  /*GrMapWindow(subsubwin2);*/
  GrMapWindow(subwindow2);
  GrMapWindow(window2);
  
  while(1) {
    GrGetNextEvent(&event);
    
    switch (event.type) {
    case GR_EVENT_TYPE_NONE:
      break;
    case GR_EVENT_TYPE_BUTTON_DOWN:
	offset_x = event.button.x;
	offset_y = event.button.y;

      if (event.button.changebuttons & GR_BUTTON_R) {
	GrRaiseWindow(event.button.wid);
      }
      if (event.button.wid == subsubwin1) {
	GR_WINDOW_INFO winfo;
	GrGetWindowInfo(subsubwin1, &winfo);
	if (winfo.parent == subwindow1) {
	  GrReparentWindow(subsubwin1, subwindow2, 10, 10);
	} else {
	  GrReparentWindow(subsubwin1, subwindow1, 10, 10);
	}
      }
    case GR_EVENT_TYPE_MOUSE_MOTION:
      if (event.mouse.buttons == GR_BUTTON_L && 
	  (event.mouse.wid == window1 || event.mouse.wid == window2)) {
	GrMoveWindow(event.mouse.wid, 
		     event.mouse.rootx - offset_x, 
		     event.mouse.rooty - offset_y);
      }
      if (event.mouse.buttons == GR_BUTTON_R) {
	GrResizeWindow(event.mouse.wid, 
		     event.mouse.x + 1, 
		     event.mouse.y + 1);
      }
      break;
    case GR_EVENT_TYPE_EXPOSURE:
      /*GrFillRect(event.exposure.wid, defgc,
	event.exposure.x, event.exposure.y,
	event.exposure.width, event.exposure.height);*/
      break;
    case GR_EVENT_TYPE_CLOSE_REQ:
      GrClose();
      exit(0);
    default:
      fprintf(stderr, "%d\n", event.type);
    }
  }
  GrClose();
}