Exemplo n.º 1
0
/* The code that handles single-instance and startup notification is
 * copied from gedit.
 *
 * Copyright (C) 2005 - Paolo Maggi 
 */
static void
on_bacon_message_received (const char *message,
			   gpointer    data)
{
	GtkWidget *window = data;
	guint32    startup_timestamp;

	g_return_if_fail (message != NULL);

	DEBUG ("Other instance launched, presenting the main window. message='%s'",
		message);

	startup_timestamp = atoi (message);

	/* Set the proper interaction time on the window.
	 * Fall back to roundtripping to the X server when we
	 * don't have the timestamp, e.g. when launched from
	 * terminal. We also need to make sure that the window
	 * has been realized otherwise it will not work. lame. */
	if (startup_timestamp == 0) {
		/* Work if launched from the terminal */
		DEBUG ("Using X server timestamp as a fallback");

		if (!GTK_WIDGET_REALIZED (window)) {
			gtk_widget_realize (GTK_WIDGET (window));
		}

		startup_timestamp = gdk_x11_get_server_time (window->window);
	}

	gtk_window_present_with_time (GTK_WINDOW (window), startup_timestamp);
}
Exemplo n.º 2
0
static void
egg_tray_manager_unmanage (EggTrayManager *manager)
{
#ifdef GDK_WINDOWING_X11
  Display *display;
  guint32 timestamp;
  GtkWidget *invisible;

  if (manager->invisible == NULL)
    return;

  invisible = manager->invisible;
  g_assert (GTK_IS_INVISIBLE (invisible));
  g_assert (GTK_WIDGET_REALIZED (invisible));
  g_assert (GDK_IS_WINDOW (invisible->window));
  
  display = GDK_WINDOW_XDISPLAY (invisible->window);
  
  if (XGetSelectionOwner (display, manager->selection_atom) ==
      GDK_WINDOW_XWINDOW (invisible->window))
    {
      timestamp = gdk_x11_get_server_time (invisible->window);      
      XSetSelectionOwner (display, manager->selection_atom, None, timestamp);
    }

  gdk_window_remove_filter (invisible->window, egg_tray_manager_window_filter, manager);  

  manager->invisible = NULL; /* prior to destroy for reentrancy paranoia */
  gtk_widget_destroy (invisible);
  g_object_unref (G_OBJECT (invisible));
#endif
}
Exemplo n.º 3
0
static void
tomboy_window_override_user_time (GtkWindow *window)
{
#ifdef GDK_WINDOWING_X11
	guint32 ev_time = gtk_get_current_event_time();

	if (ev_time == 0) {
		/* 
		 * FIXME: Global keypresses use an event filter on the root
		 * window, which processes events before GDK sees them.
		 */
		ev_time = tomboy_keybinder_get_current_event_time ();
	}
	if (ev_time == 0) {
		gint ev_mask = gtk_widget_get_events (GTK_WIDGET(window));
		if (!(ev_mask & GDK_PROPERTY_CHANGE_MASK)) {
			gtk_widget_add_events (GTK_WIDGET (window),
					       GDK_PROPERTY_CHANGE_MASK);
		}

		/* 
		 * NOTE: Last resort for D-BUS or other non-interactive
		 *       openings.  Causes roundtrip to server.  Lame. 
		 */
		ev_time = gdk_x11_get_server_time (gtk_widget_get_window(GTK_WIDGET(window)));
	}

	TRACE (g_print("Setting _NET_WM_USER_TIME to: %d\n", ev_time));
	gdk_x11_window_set_user_time (gtk_widget_get_window(GTK_WIDGET(window)), ev_time);
#endif
}
Exemplo n.º 4
0
/**
 * ev_application_open_window:
 * @application: The instance of the application.
 * @timestamp: Current time value.
 *
 * Creates a new window
 */
void
ev_application_open_window (EvApplication *application,
			    GdkScreen     *screen,
			    guint32        timestamp)
{
	GtkWidget *new_window = ev_window_new ();
#ifdef GDK_WINDOWING_X11
	GdkWindow *gdk_window;
#endif

	if (screen) {
		ev_stock_icons_set_screen (screen);
		gtk_window_set_screen (GTK_WINDOW (new_window), screen);
	}

	if (!gtk_widget_get_realized (new_window))
		gtk_widget_realize (new_window);

#ifdef GDK_WINDOWING_X11
	gdk_window = gtk_widget_get_window (GTK_WIDGET (new_window));

	if (timestamp <= 0)
		timestamp = gdk_x11_get_server_time (gdk_window);
	gdk_x11_window_set_user_time (gdk_window, timestamp);

	gtk_window_present (GTK_WINDOW (new_window));
#else
	gtk_window_present_with_time (GTK_WINDOW (new_window), timestamp);
#endif /* GDK_WINDOWING_X11 */
}
Exemplo n.º 5
0
void invoke(const gchar *cmd, const gchar *desktop, gboolean with_pkexec)
{
   GdkAppLaunchContext *context;
   GAppInfo *appinfo;
   GError *error = NULL;
   static GtkWidget *w = NULL;

   // pkexec
   if(with_pkexec || FORCE_PKEXEC) {
      invoke_with_pkexec(cmd);
      return;
   }

   // fake window to get the current server time *urgh*
   if (!w) {
      w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
      gtk_widget_realize (w);
   }

   // normal launch
   context = gdk_display_get_app_launch_context (gdk_display_get_default ());
   guint32 timestamp =  gdk_x11_get_server_time (gtk_widget_get_window (w));
   appinfo = g_app_info_create_from_commandline(cmd, 
						cmd, 
						G_APP_INFO_CREATE_NONE,
						&error);
   gdk_app_launch_context_set_timestamp (context, timestamp);
   if (!g_app_info_launch (appinfo, NULL, (GAppLaunchContext*)context, &error))
      g_warning ("Launching failed: %s", error->message);
   g_object_unref (context);
   g_object_unref (appinfo);

}
Exemplo n.º 6
0
static void
egg_tray_icon_send_manager_message (EggTrayIcon *icon,
				    long         message,
				    Window       window,
				    long         data1,
				    long         data2,
				    long         data3)
{
  XClientMessageEvent ev;
  Display *display;
  
  ev.type = ClientMessage;
  ev.window = window;
  ev.message_type = icon->system_tray_opcode_atom;
  ev.format = 32;
  ev.data.l[0] = gdk_x11_get_server_time (GTK_WIDGET (icon)->window);
  ev.data.l[1] = message;
  ev.data.l[2] = data1;
  ev.data.l[3] = data2;
  ev.data.l[4] = data3;

  display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon)));
  
  gdk_error_trap_push ();
  XSendEvent (display,
	      icon->manager_window, False, NoEventMask, (XEvent *)&ev);
  XSync (display, False);
  gdk_error_trap_pop ();
}
Exemplo n.º 7
0
static void
show_grabbing_focus (GtkWidget *new_window)
{
	const char *startup_id = NULL;
	guint32     timestamp = 0;

	gtk_widget_realize (new_window);

	startup_id = g_getenv ("DESKTOP_STARTUP_ID");
	if (startup_id != NULL) {
		char *startup_id_str = g_strdup (startup_id);
		char *ts;

		ts = g_strrstr (startup_id_str, "_TIME");
		if (ts != NULL) {
			ts = ts + 5;
			errno = 0;
			timestamp = strtoul (ts, NULL, 0);
			if ((errno == EINVAL) || (errno == ERANGE))
				timestamp = 0;
		}

		g_free (startup_id_str);
	}

	if (timestamp == 0)
		timestamp = gdk_x11_get_server_time (new_window->window);
	gdk_x11_window_set_user_time (new_window->window, timestamp);

	gtk_window_present (GTK_WINDOW (new_window));
}
Exemplo n.º 8
0
void
applet_info_dialog_show (NMApplet *applet)
{
	GtkWidget *dialog;

	dialog = info_dialog_update (applet);
	if (!dialog)
		return;

	g_signal_connect (dialog, "delete-event", G_CALLBACK (gtk_widget_hide_on_delete), dialog);
	g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_hide), dialog);
	gtk_widget_realize (dialog);
	gtk_window_present_with_time (GTK_WINDOW (dialog), gdk_x11_get_server_time (dialog->window));
}
void
nma_wireless_dialog_show (NMAWirelessDialog *dialog)
{
    GtkWidget *widget;

    g_return_if_fail (NMA_IS_WIRELESS_DIALOG (dialog));

    widget = GTK_WIDGET (dialog);

    /* Prevent focus stealing */
    gtk_widget_realize (widget);
    gtk_widget_show (widget);
    gtk_window_present_with_time (GTK_WINDOW (widget), gdk_x11_get_server_time (widget->window));
}
Exemplo n.º 10
0
/* This function will make sure that tilda window becomes active (gains
 * the focus) when it is called.
 *
 * This has to be the worst possible way of making this work, but it was the
 * only way to get metacity to play nicely. All the other WM's are so nice,
 * why oh why does metacity hate us so?
 */
void tilda_window_set_active (tilda_window *tw)
{
    DEBUG_FUNCTION ("tilda_window_set_active");
    DEBUG_ASSERT (tw != NULL);

    Display *x11_display = GDK_WINDOW_XDISPLAY (gtk_widget_get_window (tw->window) );
    Window x11_window = GDK_WINDOW_XID (gtk_widget_get_window (tw->window) );
    Window x11_root_window = GDK_WINDOW_XID ( gtk_widget_get_root_window (tw->window) );
    GdkScreen *screen = gtk_widget_get_screen (tw->window);

    XEvent event;
    long mask = SubstructureRedirectMask | SubstructureNotifyMask;
    gtk_window_move (GTK_WINDOW(tw->window), config_getint ("x_pos"), config_getint ("y_pos"));
    if (gdk_x11_screen_supports_net_wm_hint (screen,
                                             gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
    {
        guint32 timestamp = gtk_get_current_event_time ();
        if (timestamp == 0) {
            timestamp = gdk_x11_get_server_time(gdk_screen_get_root_window (screen));
        }
        event.xclient.type = ClientMessage;
        event.xclient.serial = 0;
        event.xclient.send_event = True;
        event.xclient.display = x11_display;
        event.xclient.window = x11_window;
        event.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW");

        event.xclient.format = 32;
        event.xclient.data.l[0] = 2; /* pager */
        event.xclient.data.l[1] = timestamp; /* timestamp */
        event.xclient.data.l[2] = 0;
        event.xclient.data.l[3] = 0;
        event.xclient.data.l[4] = 0;

        XSendEvent (x11_display, x11_root_window, False, mask, &event);
    }
    else
    {
        /* The WM doesn't support the EWMH standards. We'll print a warning and
         * try this, though it probably won't work... */
        g_printerr (_("WARNING: Window manager (%s) does not support EWMH hints\n"),
                    gdk_x11_screen_get_window_manager_name (screen));
        XRaiseWindow (x11_display, x11_window);
    }
}
Exemplo n.º 11
0
static void
na_tray_manager_unmanage (NaTrayManager *manager)
{
#ifdef GDK_WINDOWING_X11
  GdkDisplay *display;
  guint32     timestamp;
  GtkWidget  *invisible;
  GdkWindow  *window;

  if (manager->invisible == NULL)
    return;

  invisible = manager->invisible;
  window = gtk_widget_get_window (invisible);

  g_assert (GTK_IS_INVISIBLE (invisible));
  g_assert (gtk_widget_get_realized (invisible));
  g_assert (GDK_IS_WINDOW (window));

  display = gtk_widget_get_display (invisible);

  if (gdk_selection_owner_get_for_display (display, manager->selection_atom) ==
      window)
    {
      timestamp = gdk_x11_get_server_time (window);
      gdk_selection_owner_set_for_display (display,
                                           NULL,
                                           manager->selection_atom,
                                           timestamp,
                                           TRUE);
    }

  //FIXME: we should also use gdk_remove_client_message_filter when it's
  //available
  // See bug #351254
  gdk_window_remove_filter (window,
                            na_tray_manager_window_filter, manager);

  manager->invisible = NULL; /* prior to destroy for reentrancy paranoia */
  gtk_widget_destroy (invisible);
  g_object_unref (G_OBJECT (invisible));
#endif
}
Exemplo n.º 12
0
GtkWidget *
applet_warning_dialog_show (const char *message)
{
	GtkWidget *dialog;

	dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, message, NULL);

	/* Bash focus-stealing prevention in the face */
	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
	gtk_window_set_default_icon_name (GTK_STOCK_DIALOG_ERROR);
	gtk_window_set_title (GTK_WINDOW (dialog), _("Missing resources"));
	gtk_widget_realize (dialog);
	gtk_widget_show (dialog);
	gtk_window_present_with_time (GTK_WINDOW (dialog), gdk_x11_get_server_time (dialog->window));

	g_signal_connect_swapped (dialog, "response",
	                          G_CALLBACK (gtk_widget_destroy),
	                          dialog);
	return dialog;
}
Exemplo n.º 13
0
void
applet_mobile_pin_dialog_present (GtkWidget *dialog, gboolean now)
{
	GladeXML *xml;
	GtkWidget *widget;

	g_return_if_fail (dialog != NULL);
	xml = g_object_get_data (G_OBJECT (dialog), "xml");
	g_return_if_fail (xml != NULL);

	gtk_widget_show_all (dialog);

	widget = glade_xml_get_widget (xml, "progress_hbox");
	gtk_widget_hide (widget);

	/* Hide inactive entries */

	widget = glade_xml_get_widget (xml, "code2_entry");
	if (!g_object_get_data (G_OBJECT (widget), "active")) {
		gtk_widget_hide (widget);
		widget = glade_xml_get_widget (xml, "code2_label");
		gtk_widget_hide (widget);
	}

	widget = glade_xml_get_widget (xml, "code3_entry");
	if (!g_object_get_data (G_OBJECT (widget), "active")) {
		gtk_widget_hide (widget);
		widget = glade_xml_get_widget (xml, "code3_label");
		gtk_widget_hide (widget);
	}

	/* Need to resize the dialog after hiding widgets */
	gtk_window_resize (GTK_WINDOW (dialog), 400, 100);

	/* Show the dialog */
	gtk_widget_realize (dialog);
	if (now)
		gtk_window_present_with_time (GTK_WINDOW (dialog), gdk_x11_get_server_time (dialog->window));
	else
		gtk_window_present (GTK_WINDOW (dialog));
}
/* derived from tomboy */
static void
_window_override_user_time (CsmFailWhaleDialog *window)
{
        guint32 ev_time = gtk_get_current_event_time ();

        if (ev_time == 0) {
                gint ev_mask = gtk_widget_get_events (GTK_WIDGET (window));
                if (!(ev_mask & GDK_PROPERTY_CHANGE_MASK)) {
                        gtk_widget_add_events (GTK_WIDGET (window),
                                               GDK_PROPERTY_CHANGE_MASK);
                }

                /*
                 * NOTE: Last resort for D-BUS or other non-interactive
                 *       openings.  Causes roundtrip to server.  Lame.
                 */
                ev_time = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window)));
        }

        gdk_x11_window_set_user_time (gtk_widget_get_window (GTK_WIDGET (window)), ev_time);
}
Exemplo n.º 15
0
bool
LauncherApplication::launch()
{
    if (m_appInfo == NULL) {
        return false;
    }

    GError* error = NULL;

    GdkWindow* root;
    guint32 timestamp;

    GdkDisplay* display = gdk_display_get_default();
    GObjectScopedPointer<GdkAppLaunchContext> context(gdk_display_get_app_launch_context(display));

    /* We need to take the timestamp from the X server for the
       window manager to work properly
       https://bugs.launchpad.net/unity-2d/+bug/735205 */
    /* FIXME: ultimately we should forward the timestamps from
       events that triggered the launch */
    root = gdk_x11_window_lookup_for_display(display, GDK_ROOT_WINDOW());
    timestamp = gdk_x11_get_server_time(root);

    gdk_app_launch_context_set_timestamp(context.data(), timestamp);

    g_app_info_launch(m_appInfo.data(), NULL, (GAppLaunchContext*)context.data(), &error);

    if (error != NULL) {
        UQ_WARNING << "Failed to launch application:" << error->message;
        g_error_free(error);
        return false;
    }

    /* 'launching' property becomes true for a few seconds and becomes
       false as soon as the application is launched */
    m_launching_timer.start();
    launchingChanged(true);

    return true;
}
Exemplo n.º 16
0
static GtkWidget *
get_desktop_manager_selection (GdkScreen *screen)
{
	char selection_name[32];
	GdkAtom selection_atom;
	Window selection_owner;
	GdkDisplay *display;
	GtkWidget *selection_widget;

	g_snprintf (selection_name, sizeof (selection_name),
		    "_NET_DESKTOP_MANAGER_S%d", gdk_screen_get_number (screen));
	selection_atom = gdk_atom_intern (selection_name, FALSE);
	display = gdk_screen_get_display (screen);

	selection_owner = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display),
					      gdk_x11_atom_to_xatom_for_display (display, 
										 selection_atom));
	if (selection_owner != None) {
		return NULL;
	}
	
	selection_widget = gtk_invisible_new_for_screen (screen);
	/* We need this for gdk_x11_get_server_time() */
	gtk_widget_add_events (selection_widget, GDK_PROPERTY_CHANGE_MASK);

	if (gtk_selection_owner_set_for_display (display,
						 selection_widget,
						 selection_atom,
						 gdk_x11_get_server_time (gtk_widget_get_window (selection_widget)))) {
		
		g_signal_connect (selection_widget, "selection-get",
				  G_CALLBACK (selection_get_cb), NULL);
		return selection_widget;
	}

	gtk_widget_destroy (selection_widget);
	
	return NULL;
}
Exemplo n.º 17
0
static void tray_widget_send_dock_request(struct _tray_widget_icon *widget_icon)
{
	XClientMessageEvent ev;
	ev.type = ClientMessage;
	ev.window =  widget_icon->manager_window;
	ev.message_type = widget_icon->system_tray_opcode_atom;
	ev.format = 32;
	ev.data.l[0] = gdk_x11_get_server_time(GTK_WIDGET(widget_icon)->window);
	ev.data.l[1] = 0;
	ev.data.l[2] = gtk_plug_get_id(GTK_PLUG(widget_icon));
	ev.data.l[3] = 0;
	ev.data.l[4] = 0;

	Display *display = GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(GTK_WIDGET(widget_icon)));

	gdk_error_trap_push();

	XSendEvent(display, widget_icon->manager_window, False, NoEventMask, (XEvent *) &ev);
	XSync(display, False);

	gdk_error_trap_pop();
}
Exemplo n.º 18
0
static void
ev_application_open_uri_in_window (EvApplication  *application,
				   const char     *uri,
				   EvWindow       *ev_window,
				   GdkScreen      *screen,
				   EvLinkDest     *dest,
				   EvWindowRunMode mode,
				   const gchar    *search_string,
				   guint           timestamp)
{
#ifdef GDK_WINDOWING_X11
	GdkWindow *gdk_window;
#endif

	if (screen) {
		ev_stock_icons_set_screen (screen);
		gtk_window_set_screen (GTK_WINDOW (ev_window), screen);
	}

	/* We need to load uri before showing the window, so
	   we can restore window size without flickering */
	ev_window_open_uri (ev_window, uri, dest, mode, search_string);

	if (!gtk_widget_get_realized (GTK_WIDGET (ev_window)))
		gtk_widget_realize (GTK_WIDGET (ev_window));

#ifdef GDK_WINDOWING_X11
	gdk_window = gtk_widget_get_window (GTK_WIDGET (ev_window));

	if (timestamp <= 0)
		timestamp = gdk_x11_get_server_time (gdk_window);
	gdk_x11_window_set_user_time (gdk_window, timestamp);

	gtk_window_present (GTK_WINDOW (ev_window));
#else
	gtk_window_present_with_time (GTK_WINDOW (ev_window), timestamp);
#endif /* GDK_WINDOWING_X11 */
}
Exemplo n.º 19
0
static gboolean
na_tray_manager_manage_screen_x11 (NaTrayManager *manager,
				   GdkScreen     *screen)
{
  GdkDisplay *display;
  Screen     *xscreen;
  GtkWidget  *invisible;
  char       *selection_atom_name;
  guint32     timestamp;
  
  g_return_val_if_fail (NA_IS_TRAY_MANAGER (manager), FALSE);
  g_return_val_if_fail (manager->screen == NULL, FALSE);

  /* If there's already a manager running on the screen
   * we can't create another one.
   */
#if 0
  if (na_tray_manager_check_running_screen_x11 (screen))
    return FALSE;
#endif
  
  manager->screen = screen;

  display = gdk_screen_get_display (screen);
  xscreen = GDK_SCREEN_XSCREEN (screen);
  
  invisible = gtk_invisible_new_for_screen (screen);
  gtk_widget_realize (invisible);
  
  gtk_widget_add_events (invisible,
                         GDK_PROPERTY_CHANGE_MASK | GDK_STRUCTURE_MASK);

  selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
					 gdk_screen_get_number (screen));
  manager->selection_atom = gdk_atom_intern (selection_atom_name, FALSE);
  g_free (selection_atom_name);

  manager->invisible = invisible;
  g_object_ref (G_OBJECT (manager->invisible));

  na_tray_manager_set_orientation_property (manager);
  na_tray_manager_set_visual_property (manager);
  
  timestamp = gdk_x11_get_server_time (invisible->window);

  /* Check if we could set the selection owner successfully */
  if (gdk_selection_owner_set_for_display (display,
                                           invisible->window,
                                           manager->selection_atom,
                                           timestamp,
                                           TRUE))
    {
      XClientMessageEvent xev;
      GdkAtom             opcode_atom;
      GdkAtom             message_data_atom;

      xev.type = ClientMessage;
      xev.window = RootWindowOfScreen (xscreen);
      xev.message_type = gdk_x11_get_xatom_by_name_for_display (display,
                                                                "MANAGER");

      xev.format = 32;
      xev.data.l[0] = timestamp;
      xev.data.l[1] = gdk_x11_atom_to_xatom_for_display (display,
                                                         manager->selection_atom);
      xev.data.l[2] = GDK_WINDOW_XWINDOW (invisible->window);
      xev.data.l[3] = 0;	/* manager specific data */
      xev.data.l[4] = 0;	/* manager specific data */

      XSendEvent (GDK_DISPLAY_XDISPLAY (display),
		  RootWindowOfScreen (xscreen),
		  False, StructureNotifyMask, (XEvent *)&xev);

      opcode_atom = gdk_atom_intern ("_NET_SYSTEM_TRAY_OPCODE", FALSE);
      manager->opcode_atom = gdk_x11_atom_to_xatom_for_display (display,
                                                                opcode_atom);

      message_data_atom = gdk_atom_intern ("_NET_SYSTEM_TRAY_MESSAGE_DATA",
                                           FALSE);

      /* Add a window filter */
#if 0
      /* This is for when we lose the selection of _NET_SYSTEM_TRAY_Sx */
      g_signal_connect (invisible, "selection-clear-event",
                        G_CALLBACK (na_tray_manager_selection_clear_event),
                        manager);
#endif
      /* This is for SYSTEM_TRAY_REQUEST_DOCK and SelectionClear */
      gdk_window_add_filter (invisible->window,
                             na_tray_manager_window_filter, manager);
      /* This is for SYSTEM_TRAY_BEGIN_MESSAGE and SYSTEM_TRAY_CANCEL_MESSAGE */
      gdk_display_add_client_message_filter (display, opcode_atom,
                                             na_tray_manager_handle_client_message_opcode,
                                             manager);
      /* This is for _NET_SYSTEM_TRAY_MESSAGE_DATA */
      gdk_display_add_client_message_filter (display, message_data_atom,
                                             na_tray_manager_handle_client_message_message_data,
                                             manager);
      return TRUE;
    }
  else
    {
      gtk_widget_destroy (invisible);
      g_object_unref (invisible);
      manager->invisible = NULL;

      manager->screen = NULL;
 
      return FALSE;
    }
}
Exemplo n.º 20
0
static VALUE
gdkwin_get_server_time(VALUE self)
{
    return UINT2NUM(gdk_x11_get_server_time(_SELF(self)));
}
Exemplo n.º 21
0
bool _HYSequencePane::_ProcessOSEvent (Ptr vEvent)
{
	static			bool	amScrolling = false,
							vertical;
					
	static			long   localPt_x,
						   localPt_y,	
						   originalStart,
						   originalSpan,
						   lastClick,
						   firstClick;


	if (_HYPlatformComponent::_ProcessOSEvent (vEvent)) 
		return true;	
		
	_HY_GTK_UI_Message *theMessage = (_HY_GTK_UI_Message*)vEvent;
	if (active) 
	{
		gdouble   xc, 
				  yc;

		if (gdk_event_get_coords (theMessage->theEvent,&xc,&yc))
		{
			switch (theMessage->theEvent->type)
			{
				case GDK_BUTTON_PRESS:
				case GDK_2BUTTON_PRESS:
					{
						GdkEventButton * bevent = (GdkEventButton*)theMessage->theEvent;
						
						long  globalPt_x = xc,
							  globalPt_y = yc;
							  
						localPt_x = globalPt_x-rel.left-parentWindow->allocation.x;
						localPt_y = globalPt_y-rel.top-parentWindow->allocation.y;
							  
						vertical = (localPt_x<headerWidth)&&(localPt_y>=(GetSlotHeight()+1));

						if (((GdkEventButton*)bevent)->button == 1)
						{
							if (vertical)
								ProcessVSelectionChange (localPt_x,localPt_y,bevent->state & GDK_SHIFT_MASK,bevent->state & GDK_CONTROL_MASK, false, bevent->type == GDK_2BUTTON_PRESS);
							else
								ProcessSelectionChange  (localPt_x,localPt_y,bevent->state & GDK_SHIFT_MASK,bevent->state & GDK_CONTROL_MASK);
						}
						else
						{
							if ((((GdkEventButton*)bevent)->button == 2 || ((GdkEventButton*)bevent)->button == 3 )&& (vertical&&vselection.lLength || !vertical &&selection.lLength))
							{
								ProcessContextualPopUp (globalPt_x, globalPt_y);
								return true;
							}
						}
					}
					break;
				case GDK_BUTTON_RELEASE:
				case GDK_LEAVE_NOTIFY:
				{
					if (amScrolling)
					{
						if (messageRecipient)
							((_HYTWindow*)messageRecipient)->trackMouseComponent = (Ptr)nil;
							
						/*gdk_pointer_ungrab (((GdkEventButton*)theMessage->theEvent)->time);*/
						
						if  (vertical)
						{
							_HYRect invalRectH = {parentWindow->allocation.x+rel.left,
												  parentWindow->allocation.y+rel.top+(GetSlotHeight()+1)+1,rel.left+headerWidth,rel.bottom-HY_SCROLLER_WIDTH};
							GdkRectangle irect = HYRect2GDKRect(invalRectH);
							irect.x+=parentWindow->allocation.x;
							irect.y+=parentWindow->allocation.y;
							gdk_window_invalidate_rect (parentWindow->window, &irect, false);
							if ( localPt_x<headerWidth && localPt_x>0 && lastClick>-2)
								MoveSpecies (firstClick+originalStart,lastClick+startRow);
						}
						amScrolling = false;
					}
					break;
				}
					
				case GDK_MOTION_NOTIFY:
				{
					GdkEventMotion * motEvent = (GdkEventMotion*)theMessage->theEvent;
					if (motEvent->state & GDK_BUTTON1_MASK)
					{
						if (amScrolling)
						{
							gint mousePt_x = motEvent->x - rel.left - parentWindow->allocation.x,
								 mousePt_y = motEvent->y - rel.top  - parentWindow->allocation.y;
								 
							if (vertical) // vertical scrolling
							{
								long  wHeight = rel.bottom-rel.top-HY_SCROLLER_WIDTH,
									  slotHeight = GetSlotHeight();

								if ( mousePt_y <  GetSlotHeight()+1 || localPt_y != mousePt_y || mousePt_y>wHeight )
								{
									localPt_x = mousePt_x;
									localPt_y = mousePt_y;
									
									if (mousePt_y>wHeight)
									{
										// scroll down
										if ((endRow<=speciesIndex.lLength)&&(vselection.lData[0]!=speciesIndex.lLength-1))
										{
											if (endRow-startRow<originalSpan) 
												break;
											startRow++;
											endRow++;
											_SetVScrollerPos(((double)MAX_CONTROL_VALUE*startRow)/
															 (speciesIndex.lLength-endRow+startRow+1));
											BuildPane();
											forceUpdateForScrolling = true;
											_MarkForUpdate();
											forceUpdateForScrolling = false;
											lastClick = -2;
										}
										break;
									}
									else
									{
										mousePt_y-=(GetSlotHeight()+1);
										if (mousePt_y<=slotHeight)
										{
											if (mousePt_y>=0)
											{
												if (mousePt_y<slotHeight/2)
													mousePt_y = -1;
												else
													mousePt_y = 0;
											}
											else
											{
												// scroll up
												if (startRow>0)
												{
													startRow--;
													endRow--;
													_SetVScrollerPos(((double)MAX_CONTROL_VALUE*startRow)/(speciesIndex.lLength-endRow+startRow+1));
													BuildPane();
													forceUpdateForScrolling = true;
													_MarkForUpdate();
													forceUpdateForScrolling = false;
													lastClick = -2;
												}
												break;
											}
										}
										else
											mousePt_y=(mousePt_y-(GetSlotHeight()+1))/slotHeight;
									}
										
									if ( mousePt_y<-1 || mousePt_y>= endRow-startRow ) 
										break;
										
									if (mousePt_y!=lastClick)
									{
										GdkDrawable * tempDr = GDK_DRAWABLE(parentWindow->window);
										GdkGC * tempGC = gdk_gc_new (tempDr);

										GdkColor black = HYColorToGDKColor((_HYColor){0,0,0});
										gdk_gc_set_foreground (theContext, &black);

										gdk_gc_set_function (tempGC, GDK_INVERT);
										gdk_gc_set_line_attributes (tempGC, 2, GDK_LINE_SOLID, GDK_CAP_BUTT, GDK_JOIN_MITER);
										if (lastClick>=-1)
										{
											lastClick = (GetSlotHeight()+1)+slotHeight*(lastClick+1)+rel.top+1;
											gdk_draw_line  (tempDr,tempGC,parentWindow->allocation.x+rel.left+1,parentWindow->allocation.y+lastClick,
																		  parentWindow->allocation.x+rel.left+headerWidth-1,parentWindow->allocation.y+lastClick);

										}
										
										lastClick = mousePt_y;
										
										if (lastClick+startRow != firstClick+originalStart)
										{
											mousePt_y = (GetSlotHeight()+1)+slotHeight*(lastClick+1)+rel.top+1;
											gdk_draw_line  (tempDr,tempGC,parentWindow->allocation.x+rel.left+1,parentWindow->allocation.y+mousePt_y,
																				parentWindow->allocation.x+rel.left+headerWidth-1,parentWindow->allocation.y+mousePt_y);
										}
										g_object_unref (tempGC);
									}
								}
								return true;
							}
							else // horizontal scrolling
							{
								long	rightWindowBound = _HYCanvas::GetMaxW()-HY_SCROLLER_WIDTH;
								guint32 serverTime = gdk_x11_get_server_time (parentWindow->window);
								if ( mousePt_x<headerWidth && startColumn>0 || localPt_x!=mousePt_x || mousePt_x> rightWindowBound)
								{
									forceUpdateForScrolling = true;
									if (mousePt_x<headerWidth && startColumn>0)
									{
										gint	  wx, wy;
										gdk_window_get_origin (parentWindow->window,&wx,&wy);
										wx += parentWindow->allocation.x+rel.left;
										wy += parentWindow->allocation.y+rel.top;
										do
										{
											guint32 serverTime2 = gdk_x11_get_server_time (parentWindow->window);
											if (serverTime2-serverTime < 100)
												ProcessSelectionChange (mousePt_x,mousePt_y,true,true,true);
											GdkModifierType keyDown;
											gdk_display_get_pointer (gdk_display_get_default(),NULL,&mousePt_x,&mousePt_y,&keyDown);
											mousePt_x -= wx;
											mousePt_y -= wy;
											serverTime = serverTime2;
											if ((keyDown & GDK_BUTTON1_MASK)==0)
												break;
												
											gtk_main_iteration_do(true);
										}
										while (mousePt_x<headerWidth && startColumn>0);
									}
									else
									{
										if (mousePt_x> rightWindowBound)
										{
											gint	  wx, wy;
											gdk_window_get_origin (parentWindow->window,&wx,&wy);
											wx += parentWindow->allocation.x;
											wy += parentWindow->allocation.y;
											do
											{
												guint32 serverTime2 = gdk_x11_get_server_time (parentWindow->window);
												if (serverTime2-serverTime < 100)
													ProcessSelectionChange (mousePt_x+HY_SCROLLER_WIDTH,mousePt_y,true,true,true);
												GdkModifierType keyDown;
												gdk_display_get_pointer (gdk_display_get_default(),NULL,&mousePt_x,&mousePt_y,&keyDown);
												mousePt_x -= wx;
												mousePt_y -= wy;
												serverTime = serverTime2;
												if ((keyDown & GDK_BUTTON1_MASK)==0)
													break;
													
												gtk_main_iteration_do(true);
											}
											while (mousePt_x> rightWindowBound && endColumn < columnStrings.lLength);
										}
										else
											if (serverTime-gdk_event_get_time(theMessage->theEvent) < 100)
												ProcessSelectionChange (mousePt_x,mousePt_y,true,true,true);	
									}
									
									forceUpdateForScrolling = false;
									localPt_x = mousePt_x;
									localPt_y = mousePt_y;
								}
								return true;
							}
						}					
						else
						{
							
							/*gdk_pointer_grab (parentWindow->window,false,
									  GDK_POINTER_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK,
									  NULL, NULL, (((GdkEventMotion*)theMessage->theEvent))->time);*/
											  
							if (messageRecipient)
								((_HYTWindow*)messageRecipient)->trackMouseComponent = (Ptr)((_HYComponent*)this);

							amScrolling = true;
							originalStart = startRow,
							originalSpan  = endRow-startRow;
							lastClick = -2;
							firstClick = (localPt_y-(GetSlotHeight()+1))/GetSlotHeight();
							return true;
						}					
					}
					break;
				}
			}
		}
	}


	return false;
}
Exemplo n.º 22
0
static gboolean
egg_tray_manager_manage_xscreen (EggTrayManager *manager, Screen *xscreen)
{
  GtkWidget *invisible;
  char *selection_atom_name;
  guint32 timestamp;
  GdkScreen *screen;
  
  g_return_val_if_fail (EGG_IS_TRAY_MANAGER (manager), FALSE);
  g_return_val_if_fail (manager->screen == NULL, FALSE);

  /* If there's already a manager running on the screen
   * we can't create another one.
   */
#if 0
  if (egg_tray_manager_check_running_xscreen (xscreen))
    return FALSE;
#endif
  screen = gdk_display_get_screen (gdk_x11_lookup_xdisplay (DisplayOfScreen (xscreen)),
				   XScreenNumberOfScreen (xscreen));
  manager->screen = screen;
  
  invisible = gtk_invisible_new_for_screen (screen);
  gtk_widget_realize (invisible);
  
  gtk_widget_add_events (invisible, GDK_PROPERTY_CHANGE_MASK | GDK_STRUCTURE_MASK);

  selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
					 XScreenNumberOfScreen (xscreen));
  manager->selection_atom = XInternAtom (DisplayOfScreen (xscreen), selection_atom_name, False);

  g_free (selection_atom_name);

  manager->invisible = invisible;
  g_object_ref (G_OBJECT (manager->invisible));


  manager->orientation_atom = XInternAtom (DisplayOfScreen (xscreen),
					   "_NET_SYSTEM_TRAY_ORIENTATION",
					   FALSE);
  egg_tray_manager_set_orientation_property (manager);
  egg_tray_manager_set_visual_property (manager);
  
  timestamp = gdk_x11_get_server_time (invisible->window);
  XSetSelectionOwner (DisplayOfScreen (xscreen), manager->selection_atom,
		      GDK_WINDOW_XWINDOW (invisible->window), timestamp);

  /* Check if we were could set the selection owner successfully */
  if (XGetSelectionOwner (DisplayOfScreen (xscreen), manager->selection_atom) ==
      GDK_WINDOW_XWINDOW (invisible->window))
    {
      XClientMessageEvent xev;

      xev.type = ClientMessage;
      xev.window = RootWindowOfScreen (xscreen);
      xev.message_type = XInternAtom (DisplayOfScreen (xscreen), "MANAGER", False);

      xev.format = 32;
      xev.data.l[0] = timestamp;
      xev.data.l[1] = manager->selection_atom;
      xev.data.l[2] = GDK_WINDOW_XWINDOW (invisible->window);
      xev.data.l[3] = 0;	/* manager specific data */
      xev.data.l[4] = 0;	/* manager specific data */

      XSendEvent (DisplayOfScreen (xscreen),
		  RootWindowOfScreen (xscreen),
		  False, StructureNotifyMask, (XEvent *)&xev);

      manager->opcode_atom = XInternAtom (DisplayOfScreen (xscreen),
					  "_NET_SYSTEM_TRAY_OPCODE",
					  False);

      manager->message_data_atom = XInternAtom (DisplayOfScreen (xscreen),
						"_NET_SYSTEM_TRAY_MESSAGE_DATA",
						False);

      /* Add a window filter */
      gdk_window_add_filter (invisible->window, egg_tray_manager_window_filter, manager);
      return TRUE;
    }
  else
    {
      gtk_widget_destroy (invisible);
      g_object_unref (invisible);
      manager->invisible = NULL;

      manager->screen = NULL;
 
      return FALSE;
    }
}
Exemplo n.º 23
0
/* serverside */
static void
on_message_received (const char *message,
		     gpointer    data)
{
	const PlumaEncoding *encoding = NULL;
	gchar **commands;
	gchar **params;
	gint workspace;
	gint viewport_x;
	gint viewport_y;
	gchar *display_name;
	gint screen_number;
	gint i;
	PlumaApp *app;
	PlumaWindow *window;
	GdkDisplay *display;
	GdkScreen *screen;

	g_return_if_fail (message != NULL);

	pluma_debug_message (DEBUG_APP, "Received message:\n%s\n", message);

	commands = g_strsplit (message, "\v", -1);

	/* header */
	params = g_strsplit (commands[0], "\t", 6);
	startup_timestamp = atoi (params[0]);
	display_name = params[1];
	screen_number = atoi (params[2]);
	workspace = atoi (params[3]);
	viewport_x = atoi (params[4]);
	viewport_y = atoi (params[5]);

	display = display_open_if_needed (display_name);
	if (display == NULL)
	{
		g_warning ("Could not open display %s\n", display_name);
		g_strfreev (params);
		goto out;
	}

	screen = gdk_display_get_screen (display, screen_number);

	g_strfreev (params);

	/* body */
	for (i = 1; commands[i] != NULL; i++)
	{
		params = g_strsplit (commands[i], "\t", -1);

		if (strcmp (params[0], "NEW-WINDOW") == 0)
		{
			new_window_option = TRUE;
		}
		else if (strcmp (params[0], "NEW-DOCUMENT") == 0)
		{
			new_document_option = TRUE;
		}
		else if (strcmp (params[0], "OPEN-URIS") == 0)
		{
			gint n_uris, j;
			gchar **uris;

			line_position = atoi (params[1]);

			if (params[2] != '\0')
				encoding = pluma_encoding_get_from_charset (params[2]);

			n_uris = atoi (params[3]);
			uris = g_strsplit (params[4], " ", n_uris);

			for (j = 0; j < n_uris; j++)
			{
				GFile *file;

				file = g_file_new_for_uri (uris[j]);
				file_list = g_slist_prepend (file_list, file);
			}

			file_list = g_slist_reverse (file_list);

			/* the list takes ownerhip of the strings,
			 * only free the array */
			g_free (uris);
		}
		else
		{
			g_warning ("Unexpected bacon command");
		}

		g_strfreev (params);
	}

	/* execute the commands */

	app = pluma_app_get_default ();

	if (new_window_option)
	{
		window = pluma_app_create_window (app, screen);
	}
	else
	{
		/* get a window in the current workspace (if exists) and raise it */
		window = _pluma_app_get_window_in_viewport (app,
							    screen,
							    workspace,
							    viewport_x,
							    viewport_y);
	}

	if (file_list != NULL)
	{
		_pluma_cmd_load_files_from_prompt (window,
						   file_list,
						   encoding,
						   line_position);

		if (new_document_option)
			pluma_window_create_tab (window, TRUE);
	}
	else
	{
		PlumaDocument *doc;
		doc = pluma_window_get_active_document (window);

		if (doc == NULL ||
		    !pluma_document_is_untouched (doc) ||
		    new_document_option)
			pluma_window_create_tab (window, TRUE);
	}

	/* set the proper interaction time on the window.
	 * Fall back to roundtripping to the X server when we
	 * don't have the timestamp, e.g. when launched from
	 * terminal. We also need to make sure that the window
	 * has been realized otherwise it will not work. lame.
	 */
	if (!gtk_widget_get_realized (GTK_WIDGET (window)))
		gtk_widget_realize (GTK_WIDGET (window));

	if (startup_timestamp <= 0)
		startup_timestamp = gdk_x11_get_server_time (gtk_widget_get_window (GTK_WIDGET (window)));

	gdk_x11_window_set_user_time (gtk_widget_get_window (GTK_WIDGET (window)),
				      startup_timestamp);

	gtk_window_present (GTK_WINDOW (window));

 out:
	g_strfreev (commands);

	free_command_line_data ();
}
Exemplo n.º 24
0
gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpointer data)
{
	gint fd, sock;
	gchar buf[BUFFER_LENGTH];
	gchar *command = NULL;
	struct sockaddr_in caddr;
	socklen_t caddr_len = sizeof(caddr);
	GtkWidget *window = data;
	gboolean popup = FALSE;

	fd = g_io_channel_unix_get_fd(source);
	sock = accept(fd, (struct sockaddr *)&caddr, &caddr_len);

	/* first get the command */
	while (socket_fd_gets(sock, buf, sizeof(buf)) != -1)
	{
		command = g_strdup(buf);
		geany_debug("Received IPC command from remote instance: %s", g_strstrip(command));
		g_free(command);
		if (strncmp(buf, "open", 4) == 0)
		{
			cl_options.readonly = strncmp(buf+4, "ro", 2) == 0; /* open in readonly? */
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				gsize buf_len = strlen(buf);

				/* remove trailing newline */
				if (buf_len > 0 && buf[buf_len - 1] == '\n')
					buf[buf_len - 1] = '\0';

				handle_input_filename(buf);
			}
			popup = TRUE;
		}
		else if (strncmp(buf, "doclist", 7) == 0)
		{
			gchar *doc_list = build_document_list();
			if (!EMPTY(doc_list))
				socket_fd_write_all(sock, doc_list, strlen(doc_list));
			/* send ETX (end-of-text) so reader knows to stop reading */
			socket_fd_write_all(sock, "\3", 1);
			g_free(doc_list);
		}
		else if (strncmp(buf, "line", 4) == 0)
		{
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				g_strstrip(buf); /* remove \n char */
				/* on any error we get 0 which should be safe enough as fallback */
				cl_options.goto_line = atoi(buf);
			}
		}
		else if (strncmp(buf, "column", 6) == 0)
		{
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				g_strstrip(buf); /* remove \n char */
				/* on any error we get 0 which should be safe enough as fallback */
				cl_options.goto_column = atoi(buf);
			}
		}
#ifdef G_OS_WIN32
		else if (strncmp(buf, "window", 6) == 0)
		{
#	if GTK_CHECK_VERSION(3, 0, 0)
			HWND hwnd = (HWND) gdk_win32_window_get_handle(gtk_widget_get_window(window));
#	else
			HWND hwnd = (HWND) gdk_win32_drawable_get_handle(
				GDK_DRAWABLE(gtk_widget_get_window(window)));
#	endif
			socket_fd_write(sock, (gchar *)&hwnd, sizeof(hwnd));
		}
#endif
	}

	if (popup)
	{
#ifdef GDK_WINDOWING_X11
		GdkWindow *x11_window = gtk_widget_get_window(window);

		/* Set the proper interaction time on the window. This seems necessary to make
		 * gtk_window_present() really bring the main window into the foreground on some
		 * window managers like Gnome's metacity.
		 * Code taken from Gedit. */
#	if GTK_CHECK_VERSION(3, 0, 0)
		if (GDK_IS_X11_WINDOW(x11_window))
#	endif
		{
			gdk_x11_window_set_user_time(x11_window, gdk_x11_get_server_time(x11_window));
		}
#endif
		gtk_window_present(GTK_WINDOW(window));
#ifdef G_OS_WIN32
		gdk_window_show(gtk_widget_get_window(window));
#endif
	}

	socket_fd_close(sock);

	return TRUE;
}
NS_IMETHODIMP sbNativeWindowManager::BeginResizeDrag(nsISupports *aWindow, nsIDOMMouseEvent* aEvent, PRInt32 aDirection)
{
  nsresult rv;
  PRInt32 screenX;
  PRInt32 screenY;
  PRUint16 button;
  PRUint32 server_time;
  GdkWindow* window = NULL;
  GdkWindowEdge window_edge;

  NS_ENSURE_ARG_POINTER(aWindow);
  NS_ENSURE_ARG_POINTER(aEvent);

  /* find the window that was passed in */
  rv = GetToplevelGdkWindow(aWindow, &window);
  NS_ENSURE_SUCCESS(rv, rv);

  /* get the currently pressed mouse button from the event */
  rv = aEvent->GetButton(&button);
  NS_ENSURE_SUCCESS(rv, rv);
  /* mozilla and gtk disagree about button numbering... */
  button++;

  /* to work around an old, buggy metacity we need to move ourselves */
  /* where are we? */
  gdk_window_get_position(window, &screenX, &screenY);
  /* let's move to there */
  gdk_window_move(window, screenX, screenY);


#ifdef MOUSE_POSITION_FROM_EVENT
  /* pull the mouse position out of the mozilla event */
  rv = aEvent->GetScreenX(&screenX);
  NS_ENSURE_SUCCESS(rv, rv);
  rv = aEvent->GetScreenY(&screenY);
  NS_ENSURE_SUCCESS(rv, rv);
#else
  {
    /* ask X where the mouse is */
    GdkDisplay* display = NULL;
    GdkScreen* screen = NULL;
    GdkModifierType mask;
    /* get the current (default) display */
    display = gdk_display_get_default();
    if (display == NULL) {
      return NS_ERROR_FAILURE;
    }
    /* get the current pointer position */
    gdk_display_get_pointer(display, &screen, &screenX, &screenY, &mask);
  }
#endif

  /* convert interface directions to GDK_WINDOW_EDGE* */
  switch(aDirection) {
    case sbINativeWindowManager::DIRECTION_NORTH_WEST:
      window_edge = GDK_WINDOW_EDGE_NORTH_WEST;
      break;
    case sbINativeWindowManager::DIRECTION_NORTH:
      window_edge = GDK_WINDOW_EDGE_NORTH;
      break;
    case sbINativeWindowManager::DIRECTION_NORTH_EAST:
      window_edge = GDK_WINDOW_EDGE_NORTH_EAST;
      break;
    case sbINativeWindowManager::DIRECTION_WEST:
      window_edge = GDK_WINDOW_EDGE_WEST;
      break;
    case sbINativeWindowManager::DIRECTION_EAST:
      window_edge = GDK_WINDOW_EDGE_EAST;
      break;
    case sbINativeWindowManager::DIRECTION_SOUTH_WEST:
      window_edge = GDK_WINDOW_EDGE_SOUTH_WEST;
      break;
    case sbINativeWindowManager::DIRECTION_SOUTH:
      window_edge = GDK_WINDOW_EDGE_SOUTH;
      break;
    case sbINativeWindowManager::DIRECTION_SOUTH_EAST:
      window_edge = GDK_WINDOW_EDGE_SOUTH_EAST;
      break;
    default:
      return NS_ERROR_FAILURE;
  }

  /* if I were an event, when would I happen? */
  server_time = gdk_x11_get_server_time(window);

  /* tell the window manager to start the resize */
  gdk_window_begin_resize_drag(window, window_edge, button, 
      screenX, screenY, server_time);

  return NS_OK;
}
Exemplo n.º 26
0
gboolean socket_lock_input_cb(GIOChannel *source, GIOCondition condition, gpointer data)
{
	gint fd, sock;
	gchar buf[BUFFER_LENGTH];
	struct sockaddr_in caddr;
	socklen_t caddr_len = sizeof(caddr);
	GtkWidget *window = data;
	gboolean popup = FALSE;

	fd = g_io_channel_unix_get_fd(source);
	sock = accept(fd, (struct sockaddr *)&caddr, &caddr_len);

	/* first get the command */
	while (socket_fd_gets(sock, buf, sizeof(buf)) != -1)
	{
		if (strncmp(buf, "open", 4) == 0)
		{
			cl_options.readonly = strncmp(buf+4, "ro", 2) == 0; /* open in readonly? */
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				handle_input_filename(g_strstrip(buf));
			}
			popup = TRUE;
		}
		else if (strncmp(buf, "doclist", 7) == 0)
		{
			gchar *doc_list = build_document_list();
			if (NZV(doc_list))
				socket_fd_write_all(sock, doc_list, strlen(doc_list));
			else
				/* send ETX (end-of-text) in case we have no open files, we must send anything
				 * otherwise the client would hang on reading */
				socket_fd_write_all(sock, "\3", 1);
			g_free(doc_list);
		}
		else if (strncmp(buf, "line", 4) == 0)
		{
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				g_strstrip(buf); /* remove \n char */
				/* on any error we get 0 which should be safe enough as fallback */
				cl_options.goto_line = atoi(buf);
			}
		}
		else if (strncmp(buf, "column", 6) == 0)
		{
			while (socket_fd_gets(sock, buf, sizeof(buf)) != -1 && *buf != '.')
			{
				g_strstrip(buf); /* remove \n char */
				/* on any error we get 0 which should be safe enough as fallback */
				cl_options.goto_column = atoi(buf);
			}
		}
#ifdef G_OS_WIN32
		else if (strncmp(buf, "window", 6) == 0)
		{
			HWND hwnd = (HWND) gdk_win32_drawable_get_handle(
				GDK_DRAWABLE(gtk_widget_get_window(window)));
			socket_fd_write(sock, (gchar *)&hwnd, sizeof(hwnd));
		}
#endif
	}

	if (popup)
	{
#ifdef GDK_WINDOWING_X11
		/* Set the proper interaction time on the window. This seems necessary to make
		 * gtk_window_present() really bring the main window into the foreground on some
		 * window managers like Gnome's metacity.
		 * Code taken from Gedit. */
		gdk_x11_window_set_user_time(gtk_widget_get_window(window),
			gdk_x11_get_server_time(gtk_widget_get_window(window)));
#endif
		gtk_window_present(GTK_WINDOW(window));
#ifdef G_OS_WIN32
		gdk_window_show(gtk_widget_get_window(window));
#endif
	}

	socket_fd_close(sock);

	return TRUE;
}