Exemple #1
0
// INTERACT WITH USER AND SERVER IN ORDER TO CHOOSE ACTION
void interact(int socket) {
	printf("---MENU---\n1: SHELL\n2: SCREENSHOT\n3: UPDATE\n---FIN---\n");
	
	char *input;
	int choix = 0; 
	int i;
	// GET INPUT FROM USER AND TRANSFORM IT TO AN INT
	while(choix == 0) {
		input = read_input();
		for(i = 0; i < 4; i++)
			if(strchr(input, i + '0') != NULL)
				choix = i;
	}
	// TELL TO SERVER OUR CHOICE			
	write(socket, input, BUF_SIZE); 
	free(input); 
	
	switch(choix) {
		case 1 : 
			handle_shell(socket);
		break;
		case 2: 
			get_screenshot(socket);
		break;
		case 3:
			send_update(socket);
		break;
	}
	// WE'RE DONE, BYE
	close(socket);
}
Exemple #2
0
Fichier : vo_xv.c Projet : kax4/mpv
static int control(struct vo *vo, uint32_t request, void *data)
{
    struct xvctx *ctx = vo->priv;
    struct vo_x11_state *x11 = vo->x11;
    switch (request) {
    case VOCTRL_PAUSE:
        return (ctx->is_paused = 1);
    case VOCTRL_RESUME:
        return (ctx->is_paused = 0);
    case VOCTRL_QUERY_FORMAT:
        return query_format(ctx, *((uint32_t *) data));
    case VOCTRL_DRAW_IMAGE:
        return draw_image(vo, data);
    case VOCTRL_GET_PANSCAN:
        return VO_TRUE;
    case VOCTRL_FULLSCREEN:
        vo_x11_fullscreen(vo);
        /* indended, fallthrough to update panscan on fullscreen/windowed switch */
    case VOCTRL_SET_PANSCAN:
        resize(vo);
        return VO_TRUE;
    case VOCTRL_SET_EQUALIZER: {
        vo->want_redraw = true;
        struct voctrl_set_equalizer_args *args = data;
        return vo_xv_set_eq(vo, x11->xv_port, args->name, args->value);
    }
    case VOCTRL_GET_EQUALIZER: {
        struct voctrl_get_equalizer_args *args = data;
        return vo_xv_get_eq(vo, x11->xv_port, args->name, args->valueptr);
    }
    case VOCTRL_SET_YUV_COLORSPACE:;
        struct mp_csp_details* given_cspc = data;
        int is_709 = given_cspc->format == MP_CSP_BT_709;
        vo_xv_set_eq(vo, x11->xv_port, "bt_709", is_709 * 200 - 100);
        read_xv_csp(vo);
        vo->want_redraw = true;
        return true;
    case VOCTRL_GET_YUV_COLORSPACE:;
        struct mp_csp_details* cspc = data;
        read_xv_csp(vo);
        *cspc = ctx->cached_csp;
        return true;
    case VOCTRL_ONTOP:
        vo_x11_ontop(vo);
        return VO_TRUE;
    case VOCTRL_UPDATE_SCREENINFO:
        update_xinerama_info(vo);
        return VO_TRUE;
    case VOCTRL_REDRAW_FRAME:
        return redraw_frame(vo);
    case VOCTRL_SCREENSHOT: {
        struct voctrl_screenshot_args *args = data;
        args->out_image = get_screenshot(vo);
        return true;
    }
    }
    return VO_NOTIMPL;
}
Exemple #3
0
static int control(struct vo *vo, uint32_t request, void *data)
{
    struct xvctx *ctx = vo->priv;
    switch (request) {
    case VOCTRL_GET_PANSCAN:
        return VO_TRUE;
    case VOCTRL_SET_PANSCAN:
        resize(vo);
        return VO_TRUE;
    case VOCTRL_SET_EQUALIZER: {
        vo->want_redraw = true;
        struct voctrl_set_equalizer_args *args = data;
        return xv_set_eq(vo, ctx->xv_port, args->name, args->value);
    }
    case VOCTRL_GET_EQUALIZER: {
        struct voctrl_get_equalizer_args *args = data;
        return xv_get_eq(vo, ctx->xv_port, args->name, args->valueptr);
    }
    case VOCTRL_SET_YUV_COLORSPACE:;
        struct mp_csp_details* given_cspc = data;
        int is_709 = given_cspc->format == MP_CSP_BT_709;
        xv_set_eq(vo, ctx->xv_port, "bt_709", is_709 * 200 - 100);
        read_xv_csp(vo);
        vo->want_redraw = true;
        return true;
    case VOCTRL_GET_YUV_COLORSPACE:;
        struct mp_csp_details* cspc = data;
        read_xv_csp(vo);
        *cspc = ctx->cached_csp;
        return true;
    case VOCTRL_REDRAW_FRAME:
        redraw_frame(vo);
        return true;
    case VOCTRL_SCREENSHOT: {
        struct voctrl_screenshot_args *args = data;
        args->out_image = get_screenshot(vo);
        return true;
    }
    case VOCTRL_WINDOW_TO_OSD_COORDS: {
        float *c = data;
        struct mp_rect *src = &ctx->src_rect;
        struct mp_rect *dst = &ctx->dst_rect;
        c[0] = av_clipf(c[0], dst->x0, dst->x1) - dst->x0;
        c[1] = av_clipf(c[1], dst->y0, dst->y1) - dst->y0;
        c[0] = c[0] / (dst->x1 - dst->x0) * (src->x1 - src->x0) + src->x0;
        c[1] = c[1] / (dst->y1 - dst->y0) * (src->y1 - src->y0) + src->y0;
        return VO_TRUE;
    }
    }
    int events = 0;
    int r = vo_x11_control(vo, &events, request, data);
    if (events & (VO_EVENT_EXPOSE | VO_EVENT_RESIZE))
        resize(vo);
    return r;
}
Exemple #4
0
/* RPC call to trigger a graphics update on the remote computer */
void update_remote_display(CLIENT *clnt_refresh, CLIENT *clnt_delete)
{
	int *result;
	GdkPixbuf *screenshot;
	result = (int *) deleteimage_1(NULL, clnt_delete);
	screenshot = get_screenshot(screenshot);
	gdk_pixbuf_save_to_callback(screenshot, save_func, NULL, "jpeg", NULL,
			"quality", "20", NULL);
	result = refreshdisplay_1(NULL, clnt_refresh);
	fprintf(stderr, "Taking screenshot\n");
}
Exemple #5
0
static int control(struct vo *vo, uint32_t request, void *data)
{
    struct priv *p = vo->priv;
    switch (request) {
    case VOCTRL_PAUSE:
        return p->int_pause = 1;
    case VOCTRL_RESUME:
        return p->int_pause = 0;
    case VOCTRL_QUERY_FORMAT:
        return query_format(vo, *((uint32_t *) data));
    case VOCTRL_FULLSCREEN:
        vo_x11_fullscreen(vo);
        vo_x11_clearwindow(vo, vo->x11->window);
        return VO_TRUE;
    case VOCTRL_SET_EQUALIZER:
    {
        struct voctrl_set_equalizer_args *args = data;
        return vo_x11_set_equalizer(vo, args->name, args->value);
    }
    case VOCTRL_GET_EQUALIZER:
    {
        struct voctrl_get_equalizer_args *args = data;
        return vo_x11_get_equalizer(args->name, args->valueptr);
    }
    case VOCTRL_ONTOP:
        vo_x11_ontop(vo);
        return VO_TRUE;
    case VOCTRL_UPDATE_SCREENINFO:
        update_xinerama_info(vo);
        return VO_TRUE;
    case VOCTRL_REDRAW_FRAME:
        return redraw_frame(vo);
    case VOCTRL_SCREENSHOT: {
        struct voctrl_screenshot_args *args = data;
        args->out_image = get_screenshot(vo);
        return true;
    }
    }
    return VO_NOTIMPL;
}
Exemple #6
0
static int control(struct vo *vo, uint32_t request, void *data)
{
    struct xvctx *ctx = vo->priv;
    switch (request) {
    case VOCTRL_GET_PANSCAN:
        return VO_TRUE;
    case VOCTRL_SET_PANSCAN:
        resize(vo);
        return VO_TRUE;
    case VOCTRL_SET_EQUALIZER: {
        vo->want_redraw = true;
        struct voctrl_set_equalizer_args *args = data;
        return xv_set_eq(vo, ctx->xv_port, args->name, args->value);
    }
    case VOCTRL_GET_EQUALIZER: {
        struct voctrl_get_equalizer_args *args = data;
        return xv_get_eq(vo, ctx->xv_port, args->name, args->valueptr);
    }
    case VOCTRL_GET_COLORSPACE: {
        struct mp_image_params *params = data;
        read_xv_csp(vo);
        params->colorspace = ctx->cached_csp;
        return true;
    }
    case VOCTRL_REDRAW_FRAME:
        draw_image(vo, ctx->original_image);
        return true;
    case VOCTRL_SCREENSHOT: {
        struct voctrl_screenshot_args *args = data;
        args->out_image = get_screenshot(vo);
        return true;
    }
    }
    int events = 0;
    int r = vo_x11_control(vo, &events, request, data);
    if (events & (VO_EVENT_EXPOSE | VO_EVENT_RESIZE))
        resize(vo);
    return r;
}
Exemple #7
0
int main (int argc, char **argv)
{
  gtk_init (&argc, &argv);

  read_config ();

  // Read options from command-line arguments.
  GError *error = NULL;
  GOptionContext *context;
  context = g_option_context_new (" - show X11 windows as colour mosaic");
  g_option_context_add_main_entries (context, entries, NULL);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  if (!g_option_context_parse (context, &argc, &argv, &error)) {
    g_printerr ("option parsing failed: %s\n", error->message);
    exit (1);
  }
  g_option_context_free (context);

  if(options.format && !options.read_stdin) {
    g_printerr("You must provide option --read-stdin!");
    exit(1);
  }

#ifdef X11
  atoms_init ();
#endif

  if (already_opened ()) {
    g_printerr ("Another instance of xwinmosaic is opened.\n");
    exit (1);
  }

  if (options.read_stdin) {
    if(!options.format) {
      options.show_icons = FALSE;
      options.show_desktop = FALSE;
    }
    read_stdin ();
  } else {
#ifdef X11
    // Checks whether WM supports EWMH specifications.
    if (!wm_supports_ewmh ()) {
      GtkWidget *dialog = gtk_message_dialog_new
	(NULL,
	 GTK_DIALOG_MODAL,
	 GTK_MESSAGE_ERROR,
	 GTK_BUTTONS_CLOSE,
	 "Error: your WM does not support EWMH specifications.");

      gtk_dialog_run (GTK_DIALOG (dialog));
      g_signal_connect_swapped (dialog, "response",
				G_CALLBACK (gtk_main_quit), NULL);
      return 1;
    }

    active_window = (Window *) property (gdk_x11_get_default_root_xwindow (),
					 a_NET_ACTIVE_WINDOW,
					 XA_WINDOW,
					 NULL);
#endif
  }

  if (options.color_file)
    read_colors ();

#ifdef WIN32
  if (options.persistent) {
#ifdef DEBUG
      g_printerr ("Installing Alt-Tab hook");
#endif
      install_alt_tab_hook();
  }
#endif

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "XWinMosaic");

  GdkRectangle rect = current_monitor_size ();
  width = rect.width;
  height = rect.height;

  if (options.at_pointer) {
    gdk_display_get_pointer (gdk_display_get_default (), NULL, &options.center_x, &options.center_y, NULL);

    gint monitors = gdk_screen_get_n_monitors (gdk_screen_get_default ());
    if (monitors > 1) {
      guint xm = 0, ym = 0;
      gint current_monitor = gdk_screen_get_monitor_at_point (gdk_screen_get_default (),
							      options.center_x, options.center_y);
      for (int i = 0; i < current_monitor; i++) {
	GdkRectangle mon_rect;
	gdk_screen_get_monitor_geometry (gdk_screen_get_default (), i, &mon_rect);
	xm += mon_rect.width;
	ym += mon_rect.height;
      }
      if (xm && ym) {
	options.center_x %= xm;
	options.center_y %= ym;
      }
    }

    if (options.center_x < options.box_width/2)
      options.center_x = options.box_width/2 + 1;
    else if (options.center_x > width - options.box_width/2)
      options.center_x = width - options.box_width/2 - 1;
    if (options.center_y < options.box_height/2)
      options.center_y = options.box_height/2 + 1;
    else if (options.center_y > height - options.box_height/2)
      options.center_y = height - options.box_height/2 - 1;
  } else {
    options.center_x = width/2;
    options.center_y = height/2;
  }

  gtk_window_set_default_size (GTK_WINDOW (window), width, height);
  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
  gtk_window_set_decorated (GTK_WINDOW (window), 0);
  gtk_window_set_type_hint (GTK_WINDOW (window), GDK_WINDOW_TYPE_HINT_DIALOG);
  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), 1);
  gtk_window_set_skip_pager_hint (GTK_WINDOW (window), 1);
/**/
  gtk_widget_add_events (GTK_WIDGET (window), GDK_FOCUS_CHANGE);
  g_signal_connect (G_OBJECT (window), "focus-out-event",
        	    G_CALLBACK (on_focus_change), NULL);
/**/
  layout = gtk_layout_new (NULL, NULL);
  gtk_container_add (GTK_CONTAINER (window), layout);

  if (options.screenshot) {
    gtk_window_fullscreen (GTK_WINDOW (window));

    GdkPixbuf *screenshot;
    GdkPixmap *background = NULL;
    GtkStyle *style = NULL;
    screenshot = get_screenshot ();

    gdk_pixbuf_render_pixmap_and_mask (screenshot, &background, NULL, 0);
    style = gtk_style_new ();
    style->bg_pixmap [0] = background;

    gtk_widget_set_style (window, style);
    gtk_widget_set_style (layout, style);
  }

  search = mosaic_search_box_new ();
  mosaic_box_set_font (MOSAIC_BOX (search), options.font);
  gtk_widget_set_can_focus (search, FALSE);
  GtkRequisition s_req;
  gtk_widget_size_request (search, &s_req);
  gtk_layout_put (GTK_LAYOUT (layout), search,
		  (width - s_req.width)/2, height - s_req.height - options.box_height);
  g_signal_connect (G_OBJECT (search), "changed",
		    G_CALLBACK (refilter), NULL);

  g_signal_connect (G_OBJECT (window), "key-press-event",
		    G_CALLBACK (on_key_press), NULL);
  g_signal_connect_swapped(G_OBJECT (window), "destroy",
        		   G_CALLBACK(gtk_main_quit), NULL);

  if (!options.screenshot) {
    window_shape_bitmap = (GdkDrawable *) gdk_pixmap_new (NULL, width, height, 1);
    draw_mask (window_shape_bitmap, 0);
    gtk_widget_shape_combine_mask (window, window_shape_bitmap, 0, 0);
  }

  gtk_widget_show_all (window);
  gtk_widget_hide (search);
  gtk_window_present (GTK_WINDOW (window));
  gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
  
  if (options.persistent)
    gtk_widget_hide (window);

  GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
#ifdef X11
  myown_window = GDK_WINDOW_XID (gdk_window);

  if (!options.read_stdin) {
    // Get PropertyNotify events from root window.
    XSelectInput (gdk_x11_get_default_xdisplay (),
		  gdk_x11_get_default_root_xwindow (),
		  PropertyChangeMask);
    gdk_window_add_filter (NULL, (GdkFilterFunc) event_filter, NULL);
  }
#endif
#ifdef WIN32
  myown_window = GDK_WINDOW_HWND (gdk_window);
#endif
  update_box_list ();
  draw_mosaic (GTK_LAYOUT (layout), boxes, wsize, 0,
	       options.box_width, options.box_height);

#ifdef X11
  // Window will be shown on all desktops (and so hidden in windows list)
  unsigned int desk = 0xFFFFFFFF; // -1
  XChangeProperty(gdk_x11_get_default_xdisplay (), myown_window, a_NET_WM_DESKTOP, XA_CARDINAL,
		  32, PropModeReplace, (unsigned char *)&desk, 1);
#endif

  gtk_main ();

#ifdef X11
  if (!options.read_stdin)
    XFree (wins);
#endif

  return 0;
}