示例#1
0
int grab_window(int src_x, int src_y, int width, int height)
{
	GdkWindow *window, *root;
#ifndef GTK3
	window = gdk_window_foreign_new(GDK_ROOT_WINDOW());
	root = gdk_window_foreign_new(GDK_ROOT_WINDOW());
#else
	GdkDisplay *gdpy = gdk_display_get_default();
	window = root = gdk_x11_window_foreign_new_for_display(gdpy, GDK_ROOT_WINDOW());
#endif

  GdkPixbuf *screenshot;
	GError *error = NULL;

  if (src_x + width > gdk_screen_width ())
  	width = gdk_screen_width () - src_x;
  if (src_y + height > gdk_screen_height ())
   	height = gdk_screen_height () - src_y;

	time_t now;
	time(&now);
	char path[MAXPATHLEN];
	snprintf(path, sizeof(path), "%s%i%s", "./screen-shot-window", now, ".png");
	printf("%s\n", path);
#ifndef GTK3
  screenshot = gdk_pixbuf_get_from_drawable (NULL, root, NULL, src_x, src_y, 0, 0, width, height);
#else
	screenshot = gdk_pixbuf_get_from_window(root, src_x, src_y, width, height);
#endif

	printf("----------------%d\n", gdk_pixbuf_get_rowstride(screenshot));
	gdk_pixbuf_save (screenshot, path, "png", &error, "tEXt::CREATOR", "gnome-panel-screenshot", NULL);

	return 0;
}
示例#2
0
// initiate player's window
int initializeWindow(GtkWidget **window, int player) {
    // if not valid player, raise error
    if (player != 1 && player != 2) {
        printf("Error, invalid player number window opened\n");
        return 0;
    }

    // initialize window
    *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    // set title
    char buf[50];
    sprintf(buf, "megasenha - player %d", player);
    gtk_window_set_title(GTK_WINDOW(*window), buf);

    // set size and position and connects close window with destroy function
    gtk_window_set_default_size(GTK_WINDOW(*window), 597, 177);
    gtk_container_set_border_width (GTK_CONTAINER (*window), 10);
    if(player == 1) {
        gtk_window_move(GTK_WINDOW(*window), gdk_screen_width()*1/10, gdk_screen_height()/2 - 150);
        gtk_signal_connect (GTK_OBJECT(*window), "destroy", GTK_SIGNAL_FUNC (destroy), (gpointer) "1");
    } else {
        gtk_window_move(GTK_WINDOW(*window), gdk_screen_width()*9/10 - 500, gdk_screen_height()/2 - 150);
        gtk_signal_connect (GTK_OBJECT(*window), "destroy", GTK_SIGNAL_FUNC (destroy), (gpointer) "2");
    }

    // sets and creates icons for windows and tell windows manager not to put them together
    sprintf(buf, "p%d.png", player);
    gtk_window_set_icon(GTK_WINDOW(*window), createPixbuf(buf));
    sprintf(buf, "player %d", player);
    gtk_window_set_wmclass(GTK_WINDOW (*window), buf, "megasenha"); 

    return 1;
}
static void
screenshot_fallback_get_window_rect_coords (GdkWindow *window,
                                            gboolean include_border,
                                            GdkRectangle *real_coordinates_out,
                                            GdkRectangle *screenshot_coordinates_out)
{
  gint x_orig, y_orig;
  gint width, height;
  GdkRectangle real_coordinates;

  if (include_border)
    {
      gdk_window_get_frame_extents (window, &real_coordinates);
    }
  else
    {
      real_coordinates.width = gdk_window_get_width (window);
      real_coordinates.height = gdk_window_get_height (window);
      
      gdk_window_get_origin (window, &real_coordinates.x, &real_coordinates.y);
    }

  x_orig = real_coordinates.x;
  y_orig = real_coordinates.y;
  width  = real_coordinates.width;
  height = real_coordinates.height;

  if (real_coordinates_out != NULL)
    *real_coordinates_out = real_coordinates;

  if (x_orig < 0)
    {
      width = width + x_orig;
      x_orig = 0;
    }

  if (y_orig < 0)
    {
      height = height + y_orig;
      y_orig = 0;
    }

  if (x_orig + width > gdk_screen_width ())
    width = gdk_screen_width () - x_orig;

  if (y_orig + height > gdk_screen_height ())
    height = gdk_screen_height () - y_orig;

  if (screenshot_coordinates_out != NULL)
    {
      screenshot_coordinates_out->x = x_orig;
      screenshot_coordinates_out->y = y_orig;
      screenshot_coordinates_out->width = width;
      screenshot_coordinates_out->height = height;
    }
}
示例#4
0
int grab_whole_screen()
{	
	GdkWindow *window, *root;
#ifndef GTK3
	window = gdk_window_foreign_new(GDK_ROOT_WINDOW());
	root = gdk_window_foreign_new(GDK_ROOT_WINDOW());
#else
	GdkDisplay *gdpy = gdk_display_get_default();
	window = root = gdk_x11_window_foreign_new_for_display(gdpy, GDK_ROOT_WINDOW());
#endif

  GdkPixbuf *screenshot;
  gint x_real_orig, y_real_orig;
  gint x_orig, y_orig;
  gint real_width, real_height;
  gint width, height;
	GError *error = NULL;
#ifndef GTK3
	gdk_drawable_get_size(window, &real_width, &real_height);
#else
	real_width = gdk_window_get_width(window);
	real_height = gdk_window_get_height(window); 
#endif
	gdk_window_get_origin(window, &x_real_orig, &y_real_orig);

  x_orig = x_real_orig;
  y_orig = y_real_orig;
  width = real_width;
  height = real_height;
 	if (x_orig < 0) {
  	width = width + x_orig;
    x_orig = 0;
  }
  if (y_orig < 0) {
    height = height + y_orig;
    y_orig = 0;
  }

  if (x_orig + width > gdk_screen_width ())
  	width = gdk_screen_width () - x_orig;
  if (y_orig + height > gdk_screen_height ())
   	height = gdk_screen_height () - y_orig;
	char path[MAXPATHLEN];
	time_t now;
	time(&now);
	snprintf(path, sizeof(path), "%s%i%s", "./screen-shot-whole-screen-", now, ".png");

#ifndef GTK3
	screenshot = gdk_pixbuf_get_from_drawable (NULL, root, NULL, x_orig, y_orig, 0, 0, width, height);
#else
	screenshot = gdk_pixbuf_get_from_window(root, x_orig, y_orig, width, height);
#endif

	gdk_pixbuf_save (screenshot, path, "png", &error, "tEXt::CREATOR", "gnome-panel-screenshot", NULL);
	return 0;
}
示例#5
0
static int
pager_wnck_constructor(Plugin *plug, char **fp)
{
    pager *pg;

    ENTER;
    pg = g_new0(pager, 1);
    g_return_val_if_fail(pg != NULL, 0);
    plug->priv = pg;
    pg->plugin = plug;

    plug->pwid = gtk_event_box_new();
    GTK_WIDGET_SET_FLAGS( plug->pwid, GTK_NO_WINDOW );

    pg->htable = g_hash_table_new (g_int_hash, g_int_equal);

    pg->box = wnck_pager_new(NULL);
    g_return_val_if_fail(pg->box != NULL, 0);
    //set orientation
    wnck_pager_set_orientation (WNCK_PAGER (pg->box),pg->plugin->panel->orientation);
    wnck_pager_set_n_rows (WNCK_PAGER (pg->box), 1); //pager->rows);
    wnck_pager_set_display_mode (WNCK_PAGER (pg->box),WNCK_PAGER_DISPLAY_CONTENT);
    //pager->show_names ? WNCK_PAGER_DISPLAY_NAME : WNCK_PAGER_DISPLAY_CONTENT);
    //gtk_widget_show (pg->box);
    //gtk_container_add (GTK_CONTAINER (plugin), pg->box);

    gtk_container_set_border_width (GTK_CONTAINER (pg->box), 2);
    gtk_widget_show(pg->box);

    gtk_container_set_border_width (GTK_CONTAINER (plug->pwid), 1);
    gtk_container_add(GTK_CONTAINER(plug->pwid), pg->box);
    pg->eb = pg->box;

    pg->ratio = (gfloat)gdk_screen_width() / (gfloat)gdk_screen_height();
    pg->scaley = (gfloat)pg->dh / (gfloat)gdk_screen_height();
    pg->scalex = (gfloat)pg->dw / (gfloat)gdk_screen_width();

    pager_rebuild_all(fbev, pg);
    //do_net_current_desktop(fbev, pg);
    //do_net_client_list_stacking(fbev, pg);

    gdk_window_add_filter(NULL, (GdkFilterFunc)pager_event_filter, pg );

    g_signal_connect (G_OBJECT (fbev), "current_desktop",
          G_CALLBACK (do_net_current_desktop), (gpointer) pg);
    g_signal_connect (G_OBJECT (fbev), "active_window",
          G_CALLBACK (do_net_active_window), (gpointer) pg);
    g_signal_connect (G_OBJECT (fbev), "number_of_desktops",
          G_CALLBACK (pager_rebuild_all), (gpointer) pg);
    g_signal_connect (G_OBJECT (fbev), "client_list_stacking",
          G_CALLBACK (do_net_client_list_stacking), (gpointer) pg);
    RET(1);
}
示例#6
0
static void menu_pos(GtkMenu *menu, gint *x, gint *y, gboolean *push_in,
                     GtkWidget *widget)
{
    int ox, oy, w, h;
    kano_feedback_plugin_t *plugin = lxpanel_plugin_get_data(widget);
    GtkAllocation allocation;

    gtk_widget_get_allocation(GTK_WIDGET(widget), &allocation);

    gdk_window_get_origin(gtk_widget_get_window(widget), &ox, &oy);

    /* FIXME The X origin is being truncated for some reason, reset
       it from the allocaation. */
    ox = allocation.x;

#if GTK_CHECK_VERSION(2,20,0)
    GtkRequisition requisition;
    gtk_widget_get_requisition(GTK_WIDGET(menu), &requisition);
    w = requisition.width;
    h = requisition.height;

#else
    w = GTK_WIDGET(menu)->requisition.width;
    h = GTK_WIDGET(menu)->requisition.height;
#endif
    if (panel_get_orientation(plugin->panel) == GTK_ORIENTATION_HORIZONTAL) {
        *x = ox;
        if (*x + w > gdk_screen_width())
            *x = ox + allocation.width - w;
        *y = oy - h;
        if (*y < 0)
            *y = oy + allocation.height;
    } else {
        *x = ox + allocation.width;
        if (*x > gdk_screen_width())
            *x = ox - w;
        *y = oy;
        if (*y + h >  gdk_screen_height())
            *y = oy + allocation.height - h;
    }

    /* Debugging prints */
    /*printf("widget: x,y=%d,%d  w,h=%d,%d\n", ox, oy, allocation.width, allocation.height );
    printf("w-h %d %d\n", w, h); */

    *push_in = TRUE;

    return;
}
示例#7
0
gboolean update_display_info(struct DisplayInfo* info)
{
    GError* error = NULL;
    GDBusProxy* proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION,
                                                      G_DBUS_PROXY_FLAGS_NONE,
                                                      NULL,
                                                      DISPLAY_NAME,
                                                      DISPLAY_PATH,
                                                      DISPLAY_INTERFACE,
                                                      NULL,
                                                      &error
                                                      );
    if (error == NULL) {
        GVariant* res = g_dbus_proxy_get_cached_property(proxy, "PrimaryRect");
        g_variant_get(res, "(nnqq)", &info->x, &info->y, &info->width, &info->height);
        g_debug("%dx%d(%d,%d)", info->width, info->height, info->x, info->y);
        g_object_unref(proxy);
        return TRUE;
    } else {
        g_warning("[%s] connection dbus failed: %s", __func__, error->message);
        g_clear_error(&error);
        info->x = 0;
        info->y = 0;
        info->width = gdk_screen_width();
        info->height = gdk_screen_height();
        return FALSE;
    }
}
示例#8
0
文件: menu.c 项目: paravoid/marco
static void popup_position_func(GtkMenu* menu, gint* x, gint* y, gboolean* push_in, gpointer user_data)
{
	GtkRequisition req;
	GdkPoint* pos;

	pos = user_data;

#if GTK_CHECK_VERSION (3, 0, 0)
	gtk_widget_get_preferred_size (GTK_WIDGET (menu), &req, NULL);
#else
	gtk_widget_size_request(GTK_WIDGET(menu), &req);
#endif

	*x = pos->x;
	*y = pos->y;

	if (meta_ui_get_direction() == META_UI_DIRECTION_RTL)
	{
		*x = MAX (0, *x - req.width);
	}

	/* Ensure onscreen */
	*x = CLAMP (*x, 0, MAX(0, gdk_screen_width() - req.width));
	*y = CLAMP (*y, 0, MAX(0, gdk_screen_height() - req.height));
}
示例#9
0
/********************************************************************\
 * gnc_restore_window_size                                          *
 *   restores the position and size of the given window, if these   *
 *   these parameters have been saved earlier. Does nothing if no   *
 *   saved values are found.                                        *
 *                                                                  *
 * Args: group - the preferences group to look in for saved coords  *
 *       window - the window for which the coords are to be         *
 *                restored                                          *
 * Returns: nothing                                                 *
 \*******************************************************************/
void
gnc_restore_window_size(const char *group, GtkWindow *window)
{
    gint wpos[2], wsize[2];
    GVariant *geometry;

    ENTER("");

    g_return_if_fail(group != NULL);
    g_return_if_fail(window != NULL);

    if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SAVE_GEOMETRY))
        return;

    geometry = gnc_prefs_get_value (group, GNC_PREF_LAST_GEOMETRY);
    if (g_variant_is_of_type (geometry, (const GVariantType *) "(iiii)") )
    {
        gint screen_width;
        gint screen_height;
#if GTK_CHECK_VERSION(3,22,0)
        GdkWindow *win = gdk_screen_get_root_window (gtk_window_get_screen (window));
        GdkMonitor *mon = gdk_display_get_monitor_at_window (gtk_widget_get_display (GTK_WIDGET(window)), win);
        GdkRectangle monitor_size;

        gdk_monitor_get_geometry (mon, &monitor_size);

        screen_width = monitor_size.width;
        screen_height = monitor_size.height;
#else
        screen_width = gdk_screen_width(); //default screen
        screen_height = gdk_screen_height(); //default screen
#endif
        g_variant_get (geometry, "(iiii)",
                       &wpos[0],  &wpos[1],
                       &wsize[0], &wsize[1]);
        DEBUG("geometry from preferences - wpos[0]: %d, wpos[1]: %d, wsize[0]: %d, wsize[1]: %d",
              wpos[0],  wpos[1], wsize[0], wsize[1]);

        /* (-1, -1) means no geometry was saved (default preferences value) */
        if ((wpos[0] != -1) && (wpos[1] != -1))
        {
            /* Keep the window on screen if possible */
            if (screen_width != 0)
                wpos[0] = wpos[0] % screen_width;
            if (screen_height != 0)
                wpos[1] = wpos[1] % screen_height;
            DEBUG("geometry after screen adaption - wpos[0]: %d, wpos[1]: %d, wsize[0]: %d, wsize[1]: %d",
                  wpos[0],  wpos[1], wsize[0], wsize[1]);

            gtk_window_move(window, wpos[0], wpos[1]);
        }

        /* Don't attempt to restore invalid sizes */
        if ((wsize[0] > 0) && (wsize[1] > 0))
            gtk_window_resize(window, wsize[0], wsize[1]);
    }
    g_variant_unref (geometry);

    LEAVE("");
}
示例#10
0
/********************************************************************\
 * gnc_window_adjust_for_screen                                     *
 *   adjust the window size if it is bigger than the screen size.   *
 *                                                                  *
 * Args: window - the window to adjust                              *
 * Returns: nothing                                                 *
\********************************************************************/
void
gnc_window_adjust_for_screen(GtkWindow * window)
{
    gint screen_width;
    gint screen_height;
    gint width;
    gint height;

    if (window == NULL)
        return;

    g_return_if_fail(GTK_IS_WINDOW(window));
    if (gtk_widget_get_window (GTK_WIDGET(window)) == NULL)
        return;

    screen_width = gdk_screen_width();
    screen_height = gdk_screen_height();
    width = gdk_window_get_width (gtk_widget_get_window (GTK_WIDGET(window)));
    height = gdk_window_get_height (gtk_widget_get_window (GTK_WIDGET(window)));

    if ((width <= screen_width) && (height <= screen_height))
        return;

    width = MIN(width, screen_width - 10);
    width = MAX(width, 0);

    height = MIN(height, screen_height - 10);
    height = MAX(height, 0);

    gdk_window_resize(gtk_widget_get_window (GTK_WIDGET(window)), width, height);
    gtk_widget_queue_resize(GTK_WIDGET(window));
}
void gnotify_frontend_gtk_show_dialog(gchar* title,gchar* body,GdkPixbuf* icon)
{
	GtkWidget* dialog;
	GtkWidget* message;
	gint w,h;
	
	/* create new dialog */
	dialog=gtk_dialog_new_with_buttons(title,NULL,0,
	  GTK_STOCK_OK,GTK_RESPONSE_OK,NULL);
	message=gnotify_frontend_gtk_make_message(NULL,body,icon);
	gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),message,1,1,10);
	gtk_widget_show_all(message);
	gtk_widget_realize(dialog);
	w=dialog->allocation.width;
	h=dialog->allocation.height;
	/* move window to the right position */
	gtk_window_move(GTK_WINDOW(dialog),
	  (gdk_screen_width()-w)*
		((GnotifyConfig.align_x>=0)?(GnotifyConfig.align_x<=100)?
			GnotifyConfig.align_x:100:0)/100.0,
	  (gdk_screen_height()-h)*
		((GnotifyConfig.align_y>=0)?(GnotifyConfig.align_y<=100)?
			GnotifyConfig.align_y:100:0)/100.0
	);
	gtk_dialog_run(GTK_DIALOG(dialog));
}
void gnotify_frontend_gtk_show_popup(gchar* title,gchar* body,GdkPixbuf* icon)
{
	GtkWidget* window;
	GtkWidget* message;
	
	window=gtk_window_new(GTK_WINDOW_POPUP);
	message=gnotify_frontend_gtk_make_message(title,body,icon);
	gtk_container_add(GTK_CONTAINER(window),message);
	
	gtk_widget_show_all(message);
	gtk_widget_realize(window);
	
	gtk_window_move(GTK_WINDOW(window),
	  (gdk_screen_width()-window->allocation.width)*
		((GnotifyConfig.align_x>=0)?(GnotifyConfig.align_x<=100)?
			GnotifyConfig.align_x:100:0)/100.0,
	  (gdk_screen_height()-window->allocation.height)*
		((GnotifyConfig.align_y>=0)?(GnotifyConfig.align_y<=100)?
			GnotifyConfig.align_y:100:0)/100.0
	);
	
	gtk_widget_show_all(window);
	
	g_timeout_add(GnotifyConfig.popup_timeout,get_zero,NULL);
	gtk_main();
	/* FIXME: some sleep function... */
}
示例#13
0
文件: devGTK.c 项目: cran/gtkDevice
static double pixelWidth(void)
{
    double width, widthMM;
    width = gdk_screen_width();
    widthMM = gdk_screen_width_mm();
    return ((double)widthMM / (double)width) / MM_PER_INCH;
}
示例#14
0
void ensure_fullscreen(GtkWidget* widget)
{
    gtk_widget_set_size_request(widget, gdk_screen_width(),
                                gdk_screen_height());
    g_signal_connect(widget, "size-allocate",
                     (GCallback)_ensure_fullscreen_helper, NULL);
}
示例#15
0
static void
get_menu_pos (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data)
{
	charpick_data *curr_data = data;
	GtkRequisition  reqmenu;
	gint tempx, tempy, width, height;
	gint screen_width, screen_height;
	
	gtk_widget_size_request (GTK_WIDGET (menu), &reqmenu);
	gdk_window_get_origin (GDK_WINDOW (gtk_widget_get_window(curr_data->applet)), &tempx, &tempy);
     	gdk_window_get_geometry (GDK_WINDOW (gtk_widget_get_window(curr_data->applet)), NULL, NULL,
     				 &width, &height, NULL);
     			      
     	switch (mate_panel_applet_get_orient (MATE_PANEL_APPLET (curr_data->applet))) {
     	case MATE_PANEL_APPLET_ORIENT_DOWN:
        	tempy += height;
     		break;
     	case MATE_PANEL_APPLET_ORIENT_UP:
        	tempy -= reqmenu.height;
     		break;
     	case MATE_PANEL_APPLET_ORIENT_LEFT:
     		tempx -= reqmenu.width;
		break;
     	case MATE_PANEL_APPLET_ORIENT_RIGHT:
     		tempx += width;
		break;
     	}
	screen_width = gdk_screen_width ();
     	screen_height = gdk_screen_height ();
     	*x = CLAMP (tempx, 0, MAX (0, screen_width - reqmenu.width));
     	*y = CLAMP (tempy, 0, MAX (0, screen_height - reqmenu.height));
}
示例#16
0
static void alertpanel_show(void)
{
	gint x, y, w, h, sx, sy;
	value = G_ALERTWAIT;

	inc_lock();

	sx = gdk_screen_width();
	sy = gdk_screen_height();
	gdk_window_get_origin(dialog->window, &x, &y);
	w = dialog->allocation.width;
	h = dialog->allocation.height;
	if (x < 0 || y < 0 || x + w > sx || y + h > sy) {
		debug_print("sx, sy,  x, y,  w, h = %d, %d,  %d, %d,  %d, %d\n",
			    sx, sy, x, y, w, h);
		debug_print("alert dialog position out of range\n");
		gtk_window_set_position(GTK_WINDOW(dialog),
					GTK_WIN_POS_CENTER_ALWAYS);
	}

	while ((value & G_ALERT_VALUE_MASK) == G_ALERTWAIT)
		gtk_main_iteration();

	gtk_widget_destroy(dialog);
	GTK_EVENTS_FLUSH();

	alertpanel_is_open = FALSE;
	inc_unlock();
}
示例#17
0
Error GTKWindow::GetDesktopSize(int32 &iX, int32 &iY)
{
    iX = gdk_screen_width();
    iY = gdk_screen_height();

    return kError_NoErr;
}
示例#18
0
文件: bar.c 项目: Byrnesz/ardesia-1
/*
 * Calculate the initial position.
 */
static void
calculate_initial_position (GtkWidget *ardesia_bar_window,
                            gint *x,
                            gint *y,
                            gint w_width,
                            gint w_height,
                            gint position)
{
  gint d_width = gdk_screen_width ();
  gint d_height = gdk_screen_height ();

  /* Resize if larger that screen width. */
  if (w_width>d_width)
    {
      w_width = d_width;
      gtk_window_resize (GTK_WINDOW (ardesia_bar_window), w_width, w_height);
    }

  /* Resize if larger that screen height. */
  if (w_height>d_height)
    {
      gint tollerance = 15;
      w_height = d_height - tollerance;
      gtk_widget_set_size_request (ardesia_bar_window, w_width, w_height);
    }

  calculate_position (ardesia_bar_window, d_width, d_height, x, y, w_width, w_height, position);
}
示例#19
0
文件: migrate.c 项目: GNOME/galeon
/**
 *  This function gets the dpi in the same way that mozilla gets the dpi, 
 *  this allows us to convert from pixels to points easily
 */
static gint
mozilla_get_dpi (void)
{
	GtkSettings* settings = gtk_settings_get_default ();
	gint dpi = 0;
	char *val;
	float screenWidthIn;

	/* Use the gtk-xft-dpi setting if it is set */
	if (g_object_class_find_property (G_OBJECT_GET_CLASS (G_OBJECT (settings)),
					  "gtk-xft-dpi"))
	{
		g_object_get (G_OBJECT (settings), "gtk-xft-dpi", &dpi, NULL);
		if (dpi) return INT_ROUND (dpi / PANGO_SCALE);
	}

	/* Fall back to what xft thinks it is */
	val = XGetDefault (GDK_DISPLAY (), "Xft", "dpi");
	if (val)
	{
		char *e;
		double d = strtod(val, &e);
		if (e != val) return INT_ROUND (d);
	}
	
	/* Fall back to calculating manually from the gdk screen settings */
	screenWidthIn = ((float)gdk_screen_width_mm()) / 25.4f;
	return INT_ROUND (gdk_screen_width() / screenWidthIn);
}
示例#20
0
/* Upon realize and every resize creates a new backing pixmap of the appropriate size */
static gint
desk_configure_event (GtkWidget *widget, GdkEventConfigure *event, desk *d)
{
    Panel* p;
    int w, h;
    ENTER;
    DBG("d->no=%d %dx%d\n", d->no, widget->allocation.width, widget->allocation.height);
    if (d->pix)
        g_object_unref(d->pix);

    d->pix = gdk_pixmap_new(widget->window,
          widget->allocation.width,
          widget->allocation.height,
          -1);

    d->scalew = (gfloat)widget->allocation.height / (gfloat)gdk_screen_height();
    d->scaleh = (gfloat)widget->allocation.width  / (gfloat)gdk_screen_width();
    desk_set_dirty(d);

    p = d->pg->plugin->panel;
    //request best size
    if (p->orientation != ORIENT_HORIZ) {
        w = widget->allocation.width;
        h = (gfloat) w / d->pg->ratio;
    } else {
        h = widget->allocation.height;
        w = (gfloat) h * d->pg->ratio;
    }
    DBG("requesting %dx%d\n", w, h);
    gtk_widget_set_size_request(widget, w, h);

    RET(FALSE);
}
示例#21
0
static void
sanity_check_window_position (int *left, int *top)
{
    g_assert (left != NULL);
    g_assert (top != NULL);

    /* Make sure the top of the window is on screen, for
     * draggability (might not be necessary with all window managers,
     * but seems reasonable anyway). Make sure the top of the window
     * isn't off the bottom of the screen, or so close to the bottom
     * that it might be obscured by the panel.
     */
    *top = CLAMP (*top, 0, gdk_screen_height() - MINIMUM_ON_SCREEN_HEIGHT);

    /* FIXME bugzilla.eazel.com 669:
     * If window has negative left coordinate, set_uposition sends it
     * somewhere else entirely. Not sure what level contains this bug (XWindows?).
     * Hacked around by pinning the left edge to zero, which just means you
     * can't set a window to be partly off the left of the screen using
     * this routine.
     */
    /* Make sure the left edge of the window isn't off the right edge of
     * the screen, or so close to the right edge that it might be
     * obscured by the panel.
     */
    *left = CLAMP (*left, 0, gdk_screen_width() - MINIMUM_ON_SCREEN_WIDTH);
}
示例#22
0
static void
uni_nav_update_position (UniNav * nav)
{
    /* If the Navigation is opened, we don't have to move it again! */
    if (gtk_widget_get_visible (GTK_WIDGET (nav)))
    {
        return;
    }

    int off_x, off_y, x, y;
    GdkRectangle rect;

    /* Calculate position of popup. */
    Size pw = uni_nav_get_preview_size (nav);

    rect = gtk_image_get_current_rectangle (nav);

    /* 3 is the rectangle's line width, defined in nav->gc */
    off_x = rect.x + rect.width / 2 + 3;
    off_y = rect.y + rect.height / 2 + 3;

    x = nav->center_x - off_x;
    y = nav->center_y - off_y;

    /* Popup shoudn't be out of the screen */
    x = CLAMP (x, 0, gdk_screen_width () - pw.width);
    y = CLAMP (y, 0, gdk_screen_height () - pw.height);
    gtk_window_move (GTK_WINDOW (nav), x, y);
}
示例#23
0
static void
set_width(GtkWidget *item, gpointer bp)
{
    int widthtype;
    gboolean t;

    ENTER;

    widthtype = gtk_combo_box_get_active(GTK_COMBO_BOX(item)) + 1;
    DBG("widthtype=%d\n", widthtype);
    t = (widthtype != WIDTH_REQUEST);
    gtk_widget_set_sensitive(width_spinb, t);
    if (widthtype == WIDTH_PERCENT) {
        width_adj->upper = 100;
        width_adj->value = width_adj->upper;
    } else if  (widthtype == WIDTH_PIXEL) {
        width_adj->upper = gdk_screen_width();
        width_adj->value = width_adj->upper;
    } else
        RET();

    gtk_adjustment_changed(width_adj);
    gtk_adjustment_value_changed(width_adj);

    RET();
}
示例#24
0
文件: dialog.cpp 项目: zanqi/inkscape
void Dialog::read_geometry()
{
    _user_hidden = false;

    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    int x = prefs->getInt(_prefs_path + "/x", -1000);
    int y = prefs->getInt(_prefs_path + "/y", -1000);
    int w = prefs->getInt(_prefs_path + "/w", 0);
    int h = prefs->getInt(_prefs_path + "/h", 0);

    // g_print ("read %d %d %d %d\n", x, y, w, h);

    // If there are stored height and width values for the dialog,
    // resize the window to match; otherwise we leave it at its default
    if (w != 0 && h != 0) {
        resize(w, h);
    }

    // If there are stored values for where the dialog should be
    // located, then restore the dialog to that position.
    // also check if (x,y) is actually onscreen with the current screen dimensions
    if ( (x >= 0) && (y >= 0) && (x < (gdk_screen_width()-MIN_ONSCREEN_DISTANCE)) && (y < (gdk_screen_height()-MIN_ONSCREEN_DISTANCE)) ) {
        move(x, y);
    } else {
        // ...otherwise just put it in the middle of the screen
        set_position(Gtk::WIN_POS_CENTER);
    }

}
示例#25
0
static void
desktop_cb (gpointer             callback_data,
            guint                callback_action,
            GtkWidget           *widget)
{
  GtkWidget *window;
  GtkWidget *label;
  GdkColor desktop_color;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  set_gtk_window_type (GTK_WINDOW (window), "_NET_WM_WINDOW_TYPE_DESKTOP");
  gtk_window_set_title (GTK_WINDOW (window), "Desktop");
  gtk_widget_set_size_request (window,
                               gdk_screen_width (), gdk_screen_height ());
  gtk_window_move (GTK_WINDOW (window), 0, 0);

  desktop_color.red = 0x5144;
  desktop_color.green = 0x75D6;
  desktop_color.blue = 0xA699;

  gtk_widget_modify_bg (window, GTK_STATE_NORMAL, &desktop_color);

  label = focus_label (window);

  gtk_container_add (GTK_CONTAINER (window), label);

  gtk_widget_show_all (window);
}
示例#26
0
gint main(gint argc, gchar *argv[])
{
	GtkWidget *window;
	GtkWidget *button;
	gint width;
	gint height;
	gtk_init(&argc, &argv);

	height = gdk_screen_width();
	width = gdk_screen_height();
	/*window*/
	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	gtk_container_set_border_width(GTK_CONTAINER(window),50);
	gtk_window_set_default_size(GTK_WINDOW(window), width, height);
	g_signal_connect(G_OBJECT(window), "destroy",
			G_CALLBACK(gtk_main_quit),NULL);

	/*button*/
	button = gtk_button_new_with_label("hello");
	g_signal_connect(G_OBJECT(button), "clicked",
			G_CALLBACK(hello), NULL);
	gtk_container_add(GTK_CONTAINER(window), button);

	gtk_widget_show(button);
	gtk_widget_show(window);
	gtk_main();
	return 0;
}
示例#27
0
文件: gui.c 项目: arem/poker-network
static void gui_get_screen_size(GtkLayout* screen, gint* width, gint* height) {
  if(screen == NULL) {
    *width = gdk_screen_width();
    *height = gdk_screen_height();
  } else {
    gtk_layout_get_size(screen, (guint*)width, (guint*)height);
  }
}
示例#28
0
文件: pager.c 项目: psachin/lxpanel
/* Handler for configure_event on drawing area. */
static gboolean desk_configure_event(GtkWidget * widget, GdkEventConfigure * event, PagerDesk * d)
{
    /* Allocate pixmap and statistics buffer without border pixels. */
#if GTK_CHECK_VERSION(2,18,0)
    GtkAllocation *allocation = g_new0 (GtkAllocation, 1);
    gtk_widget_get_allocation(GTK_WIDGET(widget), allocation);
    int new_pixmap_width = allocation->width;
    int new_pixmap_height = allocation->height;
#else
    int new_pixmap_width = widget->allocation.width;
    int new_pixmap_height = widget->allocation.height;
#endif
    if ((new_pixmap_width > 0) && (new_pixmap_height > 0))
    {
        /* Allocate a new pixmap of the allocated size. */
        if (d->pixmap != NULL)
            cairo_surface_destroy(d->pixmap);
        d->pixmap = cairo_image_surface_create(CAIRO_FORMAT_RGB24, new_pixmap_width, new_pixmap_height);
        cairo_t *cr = cairo_create(d->pixmap);
        cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
        cairo_paint(cr);
	check_cairo_status(cr);
        cairo_destroy(cr);
	check_cairo_surface_status(&d->pixmap);

        /* Compute the horizontal and vertical scale factors, and mark the desktop for redraw. */
#if GTK_CHECK_VERSION(2,18,0)
        d->scale_y = (gfloat) allocation->height / (gfloat) gdk_screen_height();
        d->scale_x = (gfloat) allocation->width  / (gfloat) gdk_screen_width();
#else
        d->scale_y = (gfloat) allocation->height / (gfloat) gdk_screen_height();
        d->scale_x = (gfloat) allocation->width  / (gfloat) gdk_screen_width();
#endif
        desk_set_dirty(d);
     }

    /* Resize to optimal size. */
    gtk_widget_set_size_request(widget,
        (d->pg->plugin->panel->icon_size - BORDER_WIDTH * 2) * d->pg->aspect_ratio,
        d->pg->plugin->panel->icon_size - BORDER_WIDTH * 2);
#if GTK_CHECK_VERSION(2,18,0)
    g_free (allocation);
#endif
    return FALSE;
}
示例#29
0
gchar *
sflphone_get_display(void)
{
    int width = gdk_screen_width();
    int height = gdk_screen_height();
    char *display = getenv("DISPLAY");

    return g_strdup_printf("display://%s %dx%d", display, width, height);
}
示例#30
0
文件: osd.c 项目: iolo/liteamp
void osd_set_position(Osd * self, gint x, gint y)
{
    if (x < 0)
	x += gdk_screen_width();
    if (y < 0)
	y += gdk_screen_height();

    gtk_window_move(GTK_WINDOW(self), x, y);
}