Пример #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
/* From X Window System Interaction */
static VALUE
gdkwin_foreign_new(int argc, VALUE *argv, VALUE self)
{
    VALUE arg[2];
    GdkWindow * win = NULL;
    
    rb_scan_args(argc, argv, "11", &arg[0], &arg[1]);

    switch(argc)
    {
      case 1:
    	win = gdk_window_foreign_new(RVAL2GDKNATIVEWINDOW(arg[0]));
	break;
      case 2:
#if GTK_CHECK_VERSION(2,2,0)
    	win = gdk_window_foreign_new_for_display(RVAL2GOBJ(arg[0]),
                                                 RVAL2GDKNATIVEWINDOW(arg[1])); 
#else
    	win = gdk_window_foreign_new(NUM2UINT(arg[1])); 
        rb_warn("Not supported in GTK+-2.0.x.");
#endif 
   	break;
    }
    if (win == NULL)
        return Qnil;
    else {
        return GOBJ2RVAL(win);
    }
}
Пример #3
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;
}
// TODO: Make better use of the GDK X11 wrapper functions
GdkFilterReturn dasher_maemo_helper_handle_xevent(DasherMaemoHelper *pSelf, GdkXEvent *pXEvent) {
  DasherMaemoHelperPrivate *pPrivate = (DasherMaemoHelperPrivate *)(pSelf->private_data);
  XEvent *xev = (XEvent *) pXEvent;

  if(xev->xany.type == ClientMessage) {
//     g_message("Atom: %s %d", XGetAtomName(xev->xany.display, xev->xclient.message_type), xev->xclient.format );
    
//     for(int i(0); i < 5; ++i) {
//       g_print("%x ", (unsigned int)(xev->xclient.data.l[i]));
//     }

//     g_print("\n");
    
    if((xev->xclient.data.l[3] == 0xc) || (xev->xclient.data.l[3] == 0xd)){
      gtk_widget_show(GTK_WIDGET(pPrivate->pWindow));
      g_FRandomWindow = (Window)xev->xclient.data.l[0];
      g_FWindow = (Window)xev->xclient.data.l[1];
      g_pFocusWindow = gdk_window_foreign_new(g_FWindow);
      g_pRandomWindow = gdk_window_foreign_new(g_FRandomWindow);
#if GTK_CHECK_VERSION (2,14,0)
      gdk_window_set_transient_for(GDK_WINDOW(gtk_widget_get_window(GTK_WIDGET(pPrivate->pWindow))), g_pFocusWindow);
#else
      gdk_window_set_transient_for(GDK_WINDOW(GTK_WIDGET(pPrivate->pWindow)->window), g_pFocusWindow);
#endif
    } 

    else if((xev->xclient.data.l[3] == 0x11) || (xev->xclient.data.l[3] == 0x12))  {
      GdkEventClient sMyEvent;
      
      sMyEvent.type = GDK_CLIENT_EVENT;
      sMyEvent.window = g_pRandomWindow;
      sMyEvent.send_event = true;
      sMyEvent.message_type = gdk_atom_intern("_HILDON_IM_COM", true);
      sMyEvent.data_format = 8; // I know this is wrong...
      sMyEvent.data.l[0] = g_FRandomWindow;
      sMyEvent.data.l[1] = 0x7;
      sMyEvent.data.l[2] = 0;
      sMyEvent.data.l[3] = 0;
      sMyEvent.data.l[4] = 0;
      
      gdk_event_send_client_message((GdkEvent *)(&sMyEvent), g_FRandomWindow); 
    }
    else if(xev->xclient.data.l[3] == 0xb) {
      gtk_widget_hide(GTK_WIDGET(pPrivate->pWindow));
    }
  }
  
  return GDK_FILTER_CONTINUE;
}
void
S9xOpenGLDisplayDriver::create_window (int width, int height)
{
    XSetWindowAttributes window_attr;

    window_attr.colormap = xcolormap;
    window_attr.border_pixel = 0;
    window_attr.event_mask = StructureNotifyMask | ExposureMask;
    window_attr.background_pixmap = None;

    xwindow = XCreateWindow (display,
                             GDK_WINDOW_XWINDOW (gtk_widget_get_window (drawing_area)),
                             0,
                             0,
                             width,
                             height,
                             0,
                             vi->depth,
                             InputOutput,
                             vi->visual,
                             CWColormap | CWBorderPixel | CWBackPixmap | CWEventMask,
                             &window_attr);
    XSync (display, False);

    output_window_width = width;
    output_window_height = height;

    XMapWindow (display, xwindow);
    XSync (display, False);

    gdk_window = gdk_window_foreign_new (xwindow);
    XSync (display, False);

    gdk_window_set_user_data (gdk_window, drawing_area);
}
Пример #6
0
static void createDrawContext(GtkWidget** widget, GdkWindow** window){
  GtkWidget *main_window;
  GdkWindow *gdk_win;
  char* xwindow_s = getenv("XSCREENSAVER_WINDOW");

  if (xwindow_s != NULL) {
    // parse out the xid from xscreensaver's env var, which is given as
    // hex like 0x12023
    int xid = (int)strtol(xwindow_s, NULL, 0);

    // if we are running in xscreensaver mode, use the provided window XID
    main_window = gtk_window_new(GTK_WINDOW_POPUP);
    //main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gdk_win = gdk_window_foreign_new(xid);
    gtk_widget_show_all(main_window);
    // reparent window of main_window to gdk_win
    gdk_window_reparent(gtk_widget_get_window(main_window), gdk_win, 0, 0);
    gint width;
    gint height;
    gdk_window_get_geometry(gdk_win, NULL, NULL, &width, &height, NULL);
    printf("Looks like we are about %dx%d\n",width,height);
    // Make us cover our parent window
    gtk_window_move(GTK_WINDOW(main_window), 0, 0);
    gtk_window_set_default_size(GTK_WINDOW(main_window), width, height);
    gtk_widget_set_size_request(main_window, width, height);
  } else {
    // otherwise just get a normal window
    main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(main_window), 800, 600);
    gdk_win = gtk_widget_get_window(main_window);
  }
  *widget = main_window;
  *window = gdk_win;
}
Пример #7
0
gint title_motion_event(GtkWidget *widget, GdkEventMotion *event)
{
	gint mov_x, mov_y;
	gint win_x, win_y;

	gint xp, yp;
	GdkModifierType mask;
	static GdkWindow *root_win = NULL;

	//LOG(LOG_DEBUG, "IN : title_motion_event()");

	if((event->state & GDK_BUTTON1_MASK) &&
	   bbutton_down){

		root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ());
		gdk_window_get_pointer (root_win, &xp, &yp, &mask);

	        mov_x = xp - prev_x;
	        mov_y = yp - prev_y;

 	        gdk_window_get_root_origin(popup->window, &win_x, &win_y);

		gtk_window_move(GTK_WINDOW(popup),
				win_x + mov_x,
				win_y + mov_y);
		prev_x = xp;
		prev_y = yp;
	}

	//LOG(LOG_DEBUG, "OUT : title_motion_event()");
	return(FALSE);
}
Пример #8
0
/**
 * Makes a dialog window stay above it's parent window.
 */
static void makeDialogTransient(GtkDialog *dialog, unsigned long parentWindowId) {
    bool transientOk = false;
    
    if (parentWindowId != PLATFORM_NO_WINDOW) {
        GdkWindow *parent = gdk_window_foreign_new((GdkNativeWindow)parentWindowId);
        if (parent != NULL) {
            gtk_widget_realize(GTK_WIDGET(dialog));
#if GTK_CHECK_VERSION(2, 14, 0)
            GdkWindow *ourWindow = gtk_widget_get_window(GTK_WIDGET(dialog));
#else
            GdkWindow *ourWindow = GTK_WIDGET(dialog)->window;
#endif
            if (ourWindow != NULL) {
                gdk_window_set_transient_for(ourWindow, parent);
                transientOk = true;
                //g_object_unref(G_OBJECT(ourWindow));
            }
            g_object_unref(G_OBJECT(parent));
        }
    }
    
    if (!transientOk) {
        gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE);
    }
}
Пример #9
0
/* From X Window System Interaction */
static VALUE
rg_s_foreign_new(int argc, VALUE *argv, G_GNUC_UNUSED VALUE self)
{
    VALUE arg[2];
    GdkWindow * win = NULL;

    rb_scan_args(argc, argv, "11", &arg[0], &arg[1]);

    switch(argc)
    {
      case 1:
        win = gdk_window_foreign_new(RVAL2GDKNATIVEWINDOW(arg[0]));
        break;
      case 2:
        win = gdk_window_foreign_new_for_display(RVAL2GOBJ(arg[0]),
                                                 RVAL2GDKNATIVEWINDOW(arg[1]));
        break;
    default:
        break;
    }
    if (win == NULL)
        return Qnil;
    else {
        return GOBJ2RVAL(win);
    }
}
Пример #10
0
static GdkWindow *
lmplayer_gtk_plug_get_toplevel (GtkPlug *plug)
{
	Window root, parent, *children;
	guint nchildren;
	GdkNativeWindow xid;

	g_return_val_if_fail (GTK_IS_PLUG (plug), NULL);

	xid = gtk_plug_get_id (plug);

	do
	{
		/* FIXME: multi-head */
		if (XQueryTree (GDK_DISPLAY (), xid, &root,
					&parent, &children, &nchildren) == 0)
		{
			g_warning ("Couldn't find window manager window");
			return NULL;
		}

		if (root == parent) {
			GdkWindow *toplevel;
			toplevel = gdk_window_foreign_new (xid);
			return toplevel;
		}

		xid = parent;
	}
	while (TRUE);
}
Пример #11
0
void show_splash()
{
	gint x, y;
	GdkWindow *root_win = NULL;
	gint root_x, root_y;
	GtkWidget *vbox;
	GtkWidget *label;
	GtkWidget *frame;

#ifdef __WIN32__
	root_x = GetSystemMetrics(SM_CXSCREEN);
	root_y = GetSystemMetrics(SM_CYSCREEN);
#else
	root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ());
	gdk_window_get_size(root_win, &root_x, &root_y);
#endif

	x = (root_x - SPLASH_WIDTH) /2;
	y = (root_y - SPLASH_HEIGHT) /2;

	splash = gtk_window_new (GTK_WINDOW_POPUP);
	gtk_widget_set_size_request(splash, SPLASH_WIDTH, SPLASH_HEIGHT);
	gtk_window_move(GTK_WINDOW(splash), x, y);

	frame = gtk_frame_new(NULL);
	gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);
	gtk_container_add (GTK_CONTAINER (splash), frame);

	vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add (GTK_CONTAINER (frame), vbox);


	label = gtk_label_new(NULL);
	gtk_label_set_markup(GTK_LABEL(label), "<span size=\"x-large\" foreground=\"#a04040\" weight=\"ultrabold\">Welcome to EBView</span>");
	gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(label), TRUE, TRUE, 0);

	label = gtk_label_new(_("Loading dictionary..."));
	gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(label), TRUE, TRUE, 0);

	splash_label = gtk_label_new("");
	gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(splash_label), TRUE, TRUE, 0);

	gtk_widget_show_all(splash);

	loading_dictgroup = 1;

	tag_timeout = gtk_timeout_add(200, load_watch_thread, NULL);
	load_dictgroup_background();

	gtk_main();
}
Пример #12
0
void capture_image (char *filename)
{
	int x, y, w, h;
	gtk_window_get_frame_dimensions (window, &x, &y, &w, &h);
	gdk_window_get_origin (((GtkWidget *) window)->window, &x, &y);
	gdk_drawable_get_size (((GtkWidget *) window)->window, &w, &h);
    
	GdkWindow* root = gdk_window_foreign_new (GDK_ROOT_WINDOW ());
	GdkPixbuf* buf = gdk_pixbuf_get_from_drawable (NULL, root, NULL, x, y, 0, 0, w, h);
	GError* error = NULL;

	gdk_pixbuf_save (buf, filename, "png", &error, NULL);
	gdk_pixbuf_unref (buf);
}
Пример #13
0
	virtual void Paint2(Draw& w) {
		Size sz = GetSize();
		w.DrawRect(GetSize(), White());

		static GdkColormap* cm = gdk_x11_colormap_foreign_new(
		                              gdkx_visual_get(XVisualIDFromVisual(Xvisual)), Xcolormap);
		GdkWindow *gw = gdk_window_foreign_new(w.GetDrawable());
		GtkStyle *style = gtk_widget_get_style((GtkWidget *)gtk__parent());
		GdkRectangle r;
		r.x = r.y = 0;
		r.width = r.height = 64;
		gtk_paint_box(style, gw,
		              (GtkStateType)0, (GtkShadowType)0, &r,
		              (GtkWidget*)GTK().gtk_button_new(), "button",
		              0, 0, 64, 64);
	}
Пример #14
0
bool wxNativeContainerWindow::Create(wxNativeContainerWindowId anid)
{
    bool rc;
    GdkWindow * const win = gdk_window_foreign_new(anid);
    if ( win )
    {
        rc = Create(win);
        g_object_unref(win);
    }
    else // invalid native window id
    {
        rc = false;
    }

    return rc;
}
Пример #15
0
int16_t
NPP_HandleEvent(NPP instance, void* event) {
  InstanceData *instanceData = (InstanceData*)(instance->pdata);
  XEvent *nativeEvent = (XEvent*)event;

  if (nativeEvent->type != GraphicsExpose)
    return 0;

  XGraphicsExposeEvent *expose = &nativeEvent->xgraphicsexpose;
  instanceData->window.window = (void*)(expose->drawable);

  GdkNativeWindow nativeWinId = (XID)(instanceData->window.window);
  GdkDrawable* gdkWindow = GDK_DRAWABLE(gdk_window_foreign_new(nativeWinId));  
  drawWindow(instanceData, gdkWindow);
  g_object_unref(gdkWindow);

  return 1;
}
Пример #16
0
bool wxNativeContainerWindow::Create(wxNativeContainerWindowId anid)
{
    bool rc;
#ifdef __WXGTK3__
    GdkWindow * const win = gdk_x11_window_foreign_new_for_display(gdk_display_get_default(), anid);
#else
    GdkWindow * const win = gdk_window_foreign_new(anid);
#endif
    if ( win )
    {
        rc = Create(win);
        g_object_unref(win);
    }
    else // invalid native window id
    {
        rc = false;
    }

    return rc;
}
Пример #17
0
GdkPixbuf*
meta_gdk_pixbuf_get_from_window (GdkPixbuf   *dest,
                                 Window       xwindow,
                                 int          src_x,
                                 int          src_y,
                                 int          dest_x,
                                 int          dest_y,
                                 int          width,
                                 int          height)
{
  GdkDrawable *drawable;
  GdkPixbuf *retval;
  GdkColormap *cmap;
  
  retval = NULL;
  
  drawable = gdk_xid_table_lookup (xwindow);

  if (drawable)
    g_object_ref (G_OBJECT (drawable));
  else
    drawable = gdk_window_foreign_new (xwindow);

  cmap = get_cmap (drawable);
  
  retval = gdk_pixbuf_get_from_drawable (dest,
                                         drawable,
                                         cmap,
                                         src_x, src_y,
                                         dest_x, dest_y,
                                         width, height);

  if (cmap)
    g_object_unref (G_OBJECT (cmap));
  g_object_unref (G_OBJECT (drawable));

  return retval;
}
static void
button_clicked(GtkWidget * button,  ScreenshotData * sd)
{
    GdkPixbuf * screenshot;
    GdkPixbuf * thumbnail;
    GdkWindow * window;
    GdkNativeWindow nwindow;
    gint delay;

    gint width;
    gint height;

    gchar * filename = NULL;
    gchar * basename = NULL;
    gchar * curdir = NULL;

    
    if (sd->whole_screen) {
        window = gdk_get_default_root_window();
    } else {
        if (delay = sd->window_delay) {
            g_timeout_add(1000, delay_callback, &delay);
            gtk_main();
        }
        nwindow = select_window(gdk_screen_get_default());
        if (nwindow) {
            window = gdk_window_foreign_new(nwindow);
        } else {
            window = gdk_get_default_root_window();
        }
    }

    gdk_drawable_get_size(window, &width, &height);
    
    if (delay = sd->screenshot_delay) {
        g_timeout_add(1000, delay_callback, &delay);
        gtk_main();
    }
    
    screenshot = gdk_pixbuf_get_from_drawable (NULL,
					       window,
					       NULL, 0, 0, 0, 0,
					       width, height);
    
    thumbnail = gdk_pixbuf_scale_simple (screenshot,
				         width/5,
				         height/5, GDK_INTERP_BILINEAR);
    
    gtk_image_set_from_pixbuf (GTK_IMAGE (sd->preview), thumbnail);
    g_object_unref (thumbnail);
            filename = generate_filename_for_uri (xfce_file_chooser_get_current_folder(XFCE_FILE_CHOOSER (sd->chooser)));
    
    if (sd->ask_for_file && filename)
    {    
        gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (sd->chooser), filename);
        if (gtk_dialog_run (GTK_DIALOG (sd->chooser)) == GTK_RESPONSE_ACCEPT)
        {    
        filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER(sd->chooser));
        }
        gtk_widget_hide (GTK_WIDGET (sd->chooser));
    }
    else
    {
       /* sd->counter++;
        basename = g_strdup_printf ("Screenshot-%d.png", sd->counter);
       filename = g_build_filename (sd->screenshots_dir, basename, NULL);
        curdir = g_get_current_dir();
        filename = g_build_filename (curdir, basename, NULL);
        g_free(basename);
        */
    }
    
    if (filename) {
        gdk_pixbuf_save (screenshot, filename, "png", NULL, NULL);
        g_free (filename);
    }
}
Пример #19
0
GtkWindow* LLFilePicker::buildFilePicker(bool is_save, bool is_folder, std::string context)
{
	if (LLWindowSDL::ll_try_gtk_init() &&
	    ! gViewerWindow->getWindow()->getFullscreen())
	{
		GtkWidget *win = NULL;
		GtkFileChooserAction pickertype =
			is_save?
			(is_folder?
			 GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER :
			 GTK_FILE_CHOOSER_ACTION_SAVE) :
			(is_folder?
			 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER :
			 GTK_FILE_CHOOSER_ACTION_OPEN);

		win = gtk_file_chooser_dialog_new(NULL, NULL,
						  pickertype,
						  GTK_STOCK_CANCEL,
						   GTK_RESPONSE_CANCEL,
						  is_folder ?
						  GTK_STOCK_APPLY :
						  (is_save ? 
						   GTK_STOCK_SAVE :
						   GTK_STOCK_OPEN),
						   GTK_RESPONSE_ACCEPT,
						  (gchar *)NULL);
		mCurContextName = context;

		// get the default path for this usage context if it's been
		// seen before.
		std::map<std::string,std::string>::iterator
			this_path = mContextToPathMap.find(context);
		if (this_path != mContextToPathMap.end())
		{
			gtk_file_chooser_set_current_folder
				(GTK_FILE_CHOOSER(win),
				 this_path->second.c_str());
		}
		else if (getenv("HOME"))
		{
			gtk_file_chooser_set_current_folder
				(GTK_FILE_CHOOSER(win),
				 getenv("HOME"));
		}

#  if LL_X11
		// Make GTK tell the window manager to associate this
		// dialog with our non-GTK raw X11 window, which should try
		// to keep it on top etc.
		Window XWindowID = LLWindowSDL::get_SDL_XWindowID();
		if (None != XWindowID)
		{
			gtk_widget_realize(GTK_WIDGET(win)); // so we can get its gdkwin
			GdkWindow *gdkwin = gdk_window_foreign_new(XWindowID);
			gdk_window_set_transient_for(GTK_WIDGET(win)->window,
						     gdkwin);
		}
		else
		{
			llwarns << "Hmm, couldn't get xwid to use for transient." << llendl;
		}
#  endif //LL_X11

		g_signal_connect (GTK_FILE_CHOOSER(win),
				  "response",
				  G_CALLBACK(LLFilePicker::chooser_responder),
				  this);

		gtk_window_set_modal(GTK_WINDOW(win), TRUE);

		/* GTK 2.6: if (is_folder)
			gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(win),
			TRUE); */

		return GTK_WINDOW(win);
	}
	else
	{
		return NULL;
	}
}
Пример #20
0
	int main (int argc, char *argv[] )
	{
		GtkWidget *window, *pixmap, *fixed;
		GdkPixmap *gdk_pixmap;
		GdkBitmap *mask;
		GtkStyle *style;
		GdkGC *gc;
		CursorOffset* icon_pos;

    
		//初始化
		gtk_set_locale();
		gtk_init (&argc, &argv);

		//根窗口
		root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ());


		//建立无边界窗口
		window = gtk_window_new( GTK_WINDOW_POPUP );
		gtk_widget_set_events (window,
			gtk_widget_get_events (window) |
			GDK_BUTTON_MOTION_MASK |
			GDK_POINTER_MOTION_HINT_MASK |
			GDK_BUTTON_PRESS_MASK);
		gtk_signal_connect (GTK_OBJECT (window), "delete_event",
			GTK_SIGNAL_FUNC (close_application), NULL);
		gtk_signal_connect (GTK_OBJECT (window), "button_press_event",
			GTK_SIGNAL_FUNC (shape_pressed),NULL);
		gtk_signal_connect (GTK_OBJECT (window), "button_release_event",
			GTK_SIGNAL_FUNC (shape_released),NULL);
		gtk_signal_connect (GTK_OBJECT (window), "motion_notify_event",
			GTK_SIGNAL_FUNC (shape_motion),NULL);


		gtk_widget_show (window);

		//建立图像
		style = gtk_widget_get_default_style();
		gc = style->black_gc;
		gdk_pixmap = gdk_pixmap_create_from_xpm_d( window->window, 
			&mask, &style->bg[GTK_STATE_NORMAL], 
			xpenguin_color_xpm );
		pixmap = gtk_pixmap_new( gdk_pixmap, mask );
		gtk_widget_show( pixmap );

		//建立一个定点定位容器
		fixed = gtk_fixed_new();
		//容器的尺寸和图像一样
		gtk_widget_set_usize( fixed, 202, 240 );
		gtk_fixed_put( GTK_FIXED(fixed), pixmap, 0, 0 );
		gtk_container_add( GTK_CONTAINER(window), fixed );
		gtk_widget_show( fixed );

		//对窗口设置掩码
		gtk_widget_shape_combine_mask( window, mask, 0, 0 );

		//设置数据
		icon_pos = g_new (CursorOffset, 1);
		gtk_object_set_user_data(GTK_OBJECT(window), icon_pos);

		//设置窗口的位置
		gtk_widget_set_uposition( window, 200, 400 );
		gtk_widget_show( window );
		gtk_main ();
          
		return(0);
	}
Пример #21
0
static gint title_click_event (GtkWidget *widget, GdkEventButton *event, gpointer data)
{
	RESULT *rp;
	GdkModifierType mask;
	static GdkWindow *root_win = NULL;

	LOG(LOG_DEBUG, "IN : title_click_event()");


	if(event->type == GDK_BUTTON_PRESS){
		if ((event->button == 2) || (event->button == 3)){
			return(FALSE);
		}

		if((strcmp(data, "<") == 0) || 
		   (strcmp(data, ">") == 0)){

			if(strcmp(data, "<") == 0){
				if(g_list_previous(current_in_result) == NULL){
					return(FALSE);
				}
				current_in_result = g_list_previous(current_in_result);
			} else {
				if(g_list_next(current_in_result) == NULL){
					return(FALSE);
				}
				current_in_result = g_list_next(current_in_result);
			}

			if(current_in_result == NULL)
				return(0);
			rp = (RESULT *)(current_in_result->data);
			if(current_in_result){
				show_popup(rp);
			}

		} else if(strcmp(data, "X") == 0){
			gtk_widget_destroy(popup);
			popup = NULL;
		} else if(strcmp(data, "t") == 0){
			bbutton_down = TRUE;
			root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ());
			gdk_window_get_pointer (root_win, &prev_x, &prev_y, &mask);
			previous_x = event->x;
			previous_y = event->y;
		} else if(strcmp(data, "p") == 0){
			GdkPixbuf *pixbuf;
			bbutton_down = TRUE;

			if(bpushpin_down == FALSE){
				bpushpin_down = TRUE;

				pixbuf = create_pixbuf(IMAGE_PUSH_ON);
				gtk_image_set_from_pixbuf(GTK_IMAGE(image_pushpin), pixbuf);
				destroy_pixbuf(pixbuf);
			} else {
				bpushpin_down = FALSE;

				pixbuf = create_pixbuf(IMAGE_PUSH_OFF);
				gtk_image_set_from_pixbuf(GTK_IMAGE(image_pushpin), pixbuf);
				destroy_pixbuf(pixbuf);

				gtk_widget_destroy(popup);
				popup = NULL;

			}
		}

	} else if((event->button == 1) && (event->type == GDK_2BUTTON_PRESS)){
		// Double click
	}
	
	LOG(LOG_DEBUG, "OUT : title_click_event()");
	return(TRUE);
}
Пример #22
0
int main (int argc, char **argv)
{
    GdkWindow *rootwindow;		 /* RootWindow of X11*/
    GMainLoop *loop;                       /* the event loop */
    char *pw_dir;
    char *xml_file;
    uid_t uid;
    struct passwd *pass;

    /* inits some gdk stuff */
    gdk_init(&argc, &argv);

#ifdef ENABLE_LIBWNCK
    screen = wnck_screen_get_default ();
    wnck_screen_force_update (screen);  
#endif
  
    parse_options(&argc, &argv);
  
    uid = getuid();
    pass = getpwuid (uid);
    pw_dir = pass->pw_dir;
  
    xml_file = (char*) malloc (sizeof (char) * (strlen (XML_FILE) + strlen (pw_dir) + 1));
    sprintf (xml_file, "%s%s", pw_dir, XML_FILE);
    
    eventlist = parseDoc (xml_file);
    if (eventlist == NULL)
    {
	g_print ("xml error or no elements in list\n");
	exit (1);
    }
    free (xml_file);

    rootwindow = gdk_window_foreign_new (gdk_x11_get_default_root_xwindow());
    /*rootwindow = gdk_window_foreign_new (0x1200002); */

    if (rootwindow == NULL)
    {
	g_print ("rootwindow == NULL\n");
	exit (1);
    }
  
    /* check if GDK_BUTTON_PRESS_MASK is available */
    gdk_error_trap_push ();

    /* ... Call the X function which may cause an error here ... */
    gdk_window_set_events (rootwindow, GDK_BUTTON_PRESS_MASK);
    gdk_window_set_events (rootwindow, GDK_SCROLL_MASK);
  
    /* Flush the X queue to catch errors now. */
    gdk_flush ();

    if (gdk_error_trap_pop ())
    {
	char error[] = "grootevent: an error occured while querying the X server.\n"
	    "A window manager or an application is already grapping\n"
	    "the buttons from the root window.\n\n"
	    "Please read the documentation to get more help about this.\n";
	g_print (error);
	exit (1);
    }
    
    gdk_event_handler_set (event_func, NULL, NULL);

    loop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (loop);
   
    return 0;
}
Пример #23
0
static void create_popup_window(){

	GdkModifierType mask;
	gint pos_x, pos_y;
	gint pointer_x, pointer_y;
	gint root_x, root_y;
	GdkWindow *root_win = NULL;
	gint window_width, window_height;

	GtkWidget *vbox;
	GtkWidget *hbox;
	GtkWidget *eventbox;
	GtkWidget *image;
	GtkWidget *frame;
	GtkWidget *separator;

#ifdef __WIN32__
	HWND hWnd;
	long nStyle;
#endif

	LOG(LOG_DEBUG, "IN : create_popup_window()");

#ifdef __WIN32__
	root_x = GetSystemMetrics(SM_CXSCREEN);
	root_y = GetSystemMetrics(SM_CYSCREEN);
#else
	root_win = gdk_window_foreign_new (GDK_ROOT_WINDOW ());
	gdk_window_get_size(root_win, &root_x, &root_y);
#endif

	// If there already is an window, use that position.
	// Move if the window is out of the screen.
//	gdk_window_get_position(popup->window, &pos_x, &pos_y);
//	gtk_widget_destroy(popup);
//	redraw = TRUE;

	window_width = popup_width;
	window_height = popup_height;

	// If there is no window, determine from the mouse position.
	gdk_window_get_pointer(root_win, &pointer_x, &pointer_y, &mask);
	pos_x = pointer_x + align_x;
	pos_y = pointer_y + align_y;

	if(pos_x + window_width > root_x){
		pos_x = root_x - window_width;
	}
	
	if(bshow_popup_title) {
		if(pos_y + window_height + title_height > root_y){
			pos_y = root_y - window_height - title_height;
		}
	} else {
		if(pos_y + window_height > root_y){
			pos_y = root_y - window_height;
		}
	}

	popup = gtk_widget_new (GTK_TYPE_WINDOW,
				"type", GTK_WINDOW_TOPLEVEL,
				 "allow-shrink", TRUE,
				 "allow-grow", TRUE,
				 "default-width", window_width,
				 "default-height", window_height,

				NULL);
	gtk_window_move(GTK_WINDOW(popup), pos_x, pos_y);
	gtk_window_set_wmclass(GTK_WINDOW(popup), "Popup", "EBView");
	g_signal_connect(G_OBJECT(popup), "delete_event",
			 G_CALLBACK(close_popup), NULL);


	vbox = gtk_vbox_new(FALSE, 0);
	gtk_container_add (GTK_CONTAINER (popup), vbox);


	if(bshow_popup_title){

		frame = gtk_frame_new(NULL);
		gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
		gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 0);

		hbox = gtk_hbox_new(FALSE, 0);
		gtk_container_add( GTK_CONTAINER(frame), hbox);


		eventbox = gtk_event_box_new();
		gtk_box_pack_start(GTK_BOX(hbox), eventbox, FALSE, FALSE, 2);
		g_signal_connect(G_OBJECT(eventbox),"button_press_event",
				 G_CALLBACK(title_click_event), (gpointer)"p");
		image_pushpin = create_image(IMAGE_PUSH_OFF);
		gtk_container_add( GTK_CONTAINER(eventbox), image_pushpin);

		separator = gtk_vseparator_new();
		gtk_box_pack_start(GTK_BOX(hbox), separator, FALSE, FALSE, 0);


		eventbox = gtk_event_box_new();
		gtk_box_pack_start(GTK_BOX(hbox), eventbox, FALSE, FALSE, 2);
		g_signal_connect(G_OBJECT(eventbox),"button_press_event",
				 G_CALLBACK(title_click_event), (gpointer)"<");
		image = create_image(IMAGE_SMALL_LEFT);
		gtk_container_add( GTK_CONTAINER(eventbox), image);

		separator = gtk_vseparator_new();
		gtk_box_pack_start(GTK_BOX(hbox), separator, FALSE, FALSE, 0);

		eventbox = gtk_event_box_new();
		gtk_box_pack_start(GTK_BOX(hbox), eventbox, TRUE, TRUE, 2);
		g_signal_connect(G_OBJECT(eventbox),"button_press_event",
				 G_CALLBACK(title_click_event), (gpointer)"t");
		g_signal_connect(G_OBJECT(eventbox),"button_release_event",
				 G_CALLBACK(title_release_event), (gpointer)NULL);
		g_signal_connect(G_OBJECT(eventbox),"motion_notify_event",
				 G_CALLBACK(title_motion_event), (gpointer)NULL);

		title_label = gtk_label_new("x of x");
		gtk_container_add( GTK_CONTAINER(eventbox), title_label);

		separator = gtk_vseparator_new();
		gtk_box_pack_start(GTK_BOX(hbox), separator, FALSE, FALSE, 0);

		eventbox = gtk_event_box_new();
		gtk_box_pack_end(GTK_BOX(hbox), eventbox, FALSE, FALSE, 2);
		g_signal_connect(G_OBJECT(eventbox),"button_press_event",
				 G_CALLBACK(title_click_event), (gpointer)"X");

		image = create_image(IMAGE_SMALL_CLOSE);
		gtk_container_add( GTK_CONTAINER(eventbox), image);

		separator = gtk_vseparator_new();
		gtk_box_pack_end(GTK_BOX(hbox), separator, FALSE, FALSE, 0);

		eventbox = gtk_event_box_new();
		gtk_box_pack_end(GTK_BOX(hbox), eventbox, FALSE, FALSE, 2);
		g_signal_connect(G_OBJECT(eventbox),"button_press_event",
				 G_CALLBACK(title_click_event), (gpointer)">");

		image = create_image(IMAGE_SMALL_RIGHT);
		gtk_container_add( GTK_CONTAINER(eventbox), image);

	}

	frame = gtk_frame_new(NULL);
	gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
	gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);

	popup_scroll = gtk_scrolled_window_new (NULL, NULL);
	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (popup_scroll),
					GTK_POLICY_AUTOMATIC,
					GTK_POLICY_AUTOMATIC);

	gtk_container_add(GTK_CONTAINER(frame), popup_scroll);

	popup_view = gtk_text_view_new_with_buffer(text_buffer);
	gtk_text_view_set_editable(GTK_TEXT_VIEW(popup_view), FALSE);
	gtk_text_view_set_left_margin(GTK_TEXT_VIEW(popup_view), 5);
	gtk_text_view_set_right_margin(GTK_TEXT_VIEW(popup_view), 5);
	gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(popup_view), 3);
	gtk_text_view_set_pixels_inside_wrap(GTK_TEXT_VIEW(popup_view), 3);
	gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(popup_view), FALSE);
	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(popup_view), GTK_WRAP_WORD);


	g_signal_connect(G_OBJECT(popup_view),"motion_notify_event",
			 G_CALLBACK(motion_notify_event), (gpointer)NULL);
	
	g_signal_connect(G_OBJECT(popup_view),"button_press_event",
			 G_CALLBACK(popup_button_press_event), (gpointer)NULL);

	gtk_container_add (GTK_CONTAINER (popup_scroll), popup_view);

#ifndef __WIN32__
	gtk_widget_realize(popup);
	gdk_window_set_decorations(popup->window, 0);
#endif

	gtk_widget_show_all(popup);

#ifdef __WIN32__
	hWnd = GDK_WINDOW_HWND(popup->window);
	nStyle = GetWindowLong(hWnd, GWL_STYLE );
	nStyle &= ~WS_CAPTION;
	SetWindowLong(hWnd, GWL_STYLE, nStyle );
	SetWindowPos(hWnd,
		     HWND_TOPMOST,
		     pos_x, pos_y,
		     window_width, window_height,
		     SWP_FRAMECHANGED);
#endif

	bbutton_down = FALSE;
	bpushpin_down = FALSE;

	LOG(LOG_DEBUG, "OUT : create_popup_window()");

}
Пример #24
0
GtkWindow* LLFilePickerBase::buildFilePicker(bool is_save, bool is_folder, std::string const& folder)
{
	if (LLWindowSDL::ll_try_gtk_init())
	{
		GtkWidget *win = NULL;
		GtkFileChooserAction pickertype =
			is_save?
			(is_folder?
			 GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER :
			 GTK_FILE_CHOOSER_ACTION_SAVE) :
			(is_folder?
			 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER :
			 GTK_FILE_CHOOSER_ACTION_OPEN);

		win = gtk_file_chooser_dialog_new(NULL, NULL,
						  pickertype,
						  GTK_STOCK_CANCEL,
						   GTK_RESPONSE_CANCEL,
						  is_folder ?
						  GTK_STOCK_APPLY :
						  (is_save ? 
						   GTK_STOCK_SAVE :
						   GTK_STOCK_OPEN),
						   GTK_RESPONSE_ACCEPT,
						  (gchar *)NULL);

		if (!folder.empty())
		{
			PLS_DEBUGS << "Calling gtk_file_chooser_set_current_folder(\"" << folder << "\")." << PLS_ENDL;
			gtk_file_chooser_set_current_folder
				(GTK_FILE_CHOOSER(win),
				 folder.c_str());
		}

#  if LL_X11
		// Make GTK tell the window manager to associate this
		// dialog with our non-GTK raw X11 window, which should try
		// to keep it on top etc.
		if (mX11WindowID != None)
		{
			gtk_widget_realize(GTK_WIDGET(win)); // so we can get its gdkwin
			GdkWindow *gdkwin = gdk_window_foreign_new(mX11WindowID);
			gdk_window_set_transient_for(GTK_WIDGET(win)->window, gdkwin);
		}
#  endif //LL_X11

		g_signal_connect (GTK_FILE_CHOOSER(win),
				  "response",
				  G_CALLBACK(LLFilePickerBase::chooser_responder),
				  this);

		PLS_FLUSH;
		gtk_window_set_modal(GTK_WINDOW(win), TRUE);

		/* GTK 2.6: if (is_folder)
			gtk_file_chooser_set_show_hidden(GTK_FILE_CHOOSER(win),
			TRUE); */

		return GTK_WINDOW(win);
	}
	else
	{
		return NULL;
	}
}
Пример #25
0
void add_filter() {
  gdk_window_add_filter(gdk_window_foreign_new(GDK_ROOT_WINDOW()),
			key_filter,NULL);
}
Пример #26
0
static void
view_pixbuf (ViewerCbInfo * info, int xid, const char *color)
{
    GtkWidget *win;
    GdkColor bg_color;
    gint win_width, win_height;

    /* create toplevel window and set its title */

#ifdef ENABLE_XEMBED
    if (xid > 0) {
        GdkWindow *gdk_parent;

        win = gtk_plug_new (0);

        gdk_parent = gdk_window_foreign_new (xid);
        gdk_window_get_geometry (gdk_parent, NULL, NULL, &win_width, &win_height, NULL);

        /* so that button and key presses get registered */
        gtk_widget_add_events (win, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
    } else
#endif
    {
        char *title;

        win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

        win_width = DEFAULT_WIDTH;
        win_height = DEFAULT_HEIGHT;

        if (info->id) {
            title = g_strdup_printf ("%s#%s — %s", info->base_uri, info->id, _("SVG Viewer"));
        } else {
            title = g_strdup_printf ("%s — %s", info->base_uri,  _("SVG Viewer"));
        }
        gtk_window_set_title (GTK_WINDOW (win), title);
        g_free (title);
    }

    populate_window (win, info, xid, win_width, win_height);

    rsvg_window_set_default_icon (GTK_WINDOW (win), info->pixbuf);

    /* exit when 'X' is clicked */
    g_signal_connect (G_OBJECT (win), "destroy", G_CALLBACK (quit_cb), NULL);
    g_signal_connect (G_OBJECT (win), "delete_event", G_CALLBACK (quit_cb), NULL);

    if (color && strcmp (color, "none") != 0) {
        if (gdk_color_parse (color, &bg_color)) {
            GtkWidget *parent_widget = gtk_widget_get_parent (info->image);

            if (gdk_colormap_alloc_color
                (gtk_widget_get_colormap (parent_widget), &bg_color, FALSE, TRUE))
                gtk_widget_modify_bg (parent_widget, GTK_STATE_NORMAL, &bg_color);
            else
                g_warning (_("Couldn't allocate color '%s'"), color);
        } else
            g_warning (_("Couldn't parse color '%s'"), color);
    }

    create_popup_menu (info);

    info->window = win;
    gtk_window_add_accel_group (GTK_WINDOW (win), info->accel_group);

    g_signal_connect (G_OBJECT (win), "button-press-event", G_CALLBACK (button_press_event), info);

    gtk_widget_show_all (win);

#ifdef ENABLE_XEMBED
    if (xid > 0) {
        XReparentWindow (GDK_WINDOW_XDISPLAY (win->window),
                         GDK_WINDOW_XID (win->window), xid, 0, 0);
        XMapWindow (GDK_WINDOW_XDISPLAY (win->window), GDK_WINDOW_XID (win->window));
    }
#endif
}