popup coordinates on keyboard shortcut; Was: Re: Come fix bugs! (Batteries included)



Hi,

Attached you find my tinkerings with the 'popup menu on keyboard
shortcut' position stuff. Almost working. Only misplaced by a few pixels
and I cant figure out why. So I thought I should get more eyes to look
at it ;)

> Are you building from cvs? We should be automatically passing -Wno-
> strict-aliasing if the compiler supports it to fix this issue.

I see. Well was a quite oooold local checkout dir which I kept cvs
updating since like forever. So I cleared it out and did a fresh
checkout and voila, it worked ;)

cheers,
   Danny

-- 
www.keyserver.net key id A334AEA6

Index: fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.640
diff -u -p -r1.640 fm-directory-view.c
--- fm-directory-view.c	6 Oct 2004 19:54:32 -0000	1.640
+++ fm-directory-view.c	15 Oct 2004 16:30:03 -0000
@@ -6122,6 +6122,15 @@ void 
 fm_directory_view_pop_up_selection_context_menu  (FMDirectoryView *view, 
 						  GdkEventButton *event)
 {
+	GArray *selected_item_locations;
+	gint count;
+	GdkPoint point;
+	GdkPoint window_origin;
+	GdkPoint decoration_end;
+	GdkPoint view_in_window;
+	
+	GtkWidget *toplevel;
+	
 	g_assert (FM_IS_DIRECTORY_VIEW (view));
 
 	/* Make the context menu items not flash as they update to proper disabled,
@@ -6129,10 +6138,44 @@ fm_directory_view_pop_up_selection_conte
 	 */
 	update_menus_if_pending (view);
 
+	point.x = EEL_DEFAULT_POPUP_MENU_DISPLACEMENT;
+	point.y = EEL_DEFAULT_POPUP_MENU_DISPLACEMENT;
+	
+	selected_item_locations = fm_directory_view_get_selected_icon_locations (view);
+	if (selected_item_locations) {
+		count = selected_item_locations->len;
+		if (count > 0) {
+			point = g_array_index (selected_item_locations, GdkPoint, count - 1);
+			/* client -> root coordinates; there should be an easier way than that */
+			
+			toplevel = gtk_widget_get_toplevel (GTK_WIDGET (view));
+			if (toplevel) {
+				gdk_window_get_geometry (GTK_WIDGET (view)->window, &view_in_window.x, &view_in_window.y, 
+					NULL, NULL, NULL);
+				gdk_window_get_root_origin (toplevel->window, &window_origin.x, &window_origin.y);
+				gdk_window_get_geometry (toplevel->window, &decoration_end.x, &decoration_end.y,
+					NULL, NULL, NULL);
+					
+				window_origin.x += decoration_end.x;
+				window_origin.y += decoration_end.y;
+				window_origin.x += view_in_window.x;
+				window_origin.y += view_in_window.y;
+									
+				g_warning ("window origin %d %d", window_origin.x, window_origin.y);
+				
+				point.x += window_origin.x;
+				point.y += window_origin.y;
+			} else {
+				/* hiss */
+			}
+			
+		}
+		g_array_free (selected_item_locations, TRUE);
+	}
+
 	eel_pop_up_context_menu (create_popup_menu 
 				      	(view, FM_DIRECTORY_VIEW_POPUP_PATH_SELECTION),
-				      EEL_DEFAULT_POPUP_MENU_DISPLACEMENT,
-				      EEL_DEFAULT_POPUP_MENU_DISPLACEMENT,
+				      point.x, point.y,
 				      event);
 }
 
Index: eel-gtk-extensions.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gtk-extensions.c,v
retrieving revision 1.54
diff -u -p -r1.54 eel-gtk-extensions.c
--- eel-gtk-extensions.c	27 Oct 2003 20:10:30 -0000	1.54
+++ eel-gtk-extensions.c	15 Oct 2004 16:30:31 -0000
@@ -471,6 +471,27 @@ eel_truncate_text_for_menu_item (const c
 	return eel_str_middle_truncate (text, MAXIMUM_MENU_TITLE_LENGTH);
 }
 
+static void
+popup_menu_callback (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer userdata)
+{
+	GdkPoint *point;
+	
+	point = (GdkPoint *)userdata;
+	if (point) {
+		if (point->x != EEL_DEFAULT_POPUP_MENU_DISPLACEMENT) {
+			*x = point->x;
+		}
+		
+		if (point->y != EEL_DEFAULT_POPUP_MENU_DISPLACEMENT) {
+			*y = point->y;
+		}
+		
+		/* FIXME push_in? whats that? */
+		
+		g_free (point);
+	}
+}
+
 /**
  * eel_pop_up_context_menu:
  * 
@@ -492,13 +513,15 @@ eel_pop_up_context_menu (GtkMenu	     *m
 			      gint16	      offset_y,
 			      GdkEventButton *event)
 {
-	GdkPoint offset;
+	GdkPoint *offset;
 	int button;
 
 	g_return_if_fail (GTK_IS_MENU (menu));
+	
+	offset = (GdkPoint *) g_new0 (GdkPoint, 1);
 
-	offset.x = offset_x;
-	offset.y = offset_y;
+	offset->x = offset_x;
+	offset->y = offset_y;
 
 	/* The event button needs to be 0 if we're popping up this menu from
 	 * a button release, else a 2nd click outside the menu with any button
@@ -517,8 +540,8 @@ eel_pop_up_context_menu (GtkMenu	     *m
 	gtk_menu_popup (menu,					/* menu */
 			NULL,					/* parent_menu_shell */
 			NULL,					/* parent_menu_item */
-			NULL,
-			&offset,			        /* data */
+			(GtkMenuPositionFunc) popup_menu_callback,
+			offset,			        /* data */
 			button,					/* button */
 			event ? event->time : GDK_CURRENT_TIME); /* activate_time */
 

Attachment: signature.asc
Description: Dies ist ein digital signierter Nachrichtenteil



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]