Properly position the main menu

(Old svn revision: 4749)
This commit is contained in:
Mike Massonnet
2008-05-09 11:01:32 +00:00
parent 9731785804
commit 374c1bd30f
4 changed files with 79 additions and 2 deletions

View File

@@ -12,6 +12,8 @@ xfce4_taskmanager_SOURCES = \
main.c \ main.c \
callbacks.c \ callbacks.c \
callbacks.h \ callbacks.h \
menu-positions.c \
menu-positions.h \
functions.c \ functions.c \
functions.h \ functions.h \
interface.c \ interface.c \

View File

@@ -19,13 +19,14 @@
*/ */
#include "callbacks.h" #include "callbacks.h"
#include "menu-positions.h"
void on_button1_button_press_event(GtkButton *button, GdkEventButton *event) void on_button1_button_press_event(GtkButton *button, GdkEventButton *event)
{ {
GdkEventButton *mouseevent = (GdkEventButton *)event; GdkEventButton *mouseevent = (GdkEventButton *)event;
if(mainmenu == NULL) if(mainmenu == NULL)
mainmenu = create_mainmenu (); mainmenu = create_mainmenu();
gtk_menu_popup(GTK_MENU(mainmenu), NULL, NULL, NULL, NULL, mouseevent->button, mouseevent->time); gtk_menu_popup(GTK_MENU(mainmenu), NULL, NULL, (GtkMenuPositionFunc)position_mainmenu, button, mouseevent->button, mouseevent->time);
} }
void on_button3_toggled_event(GtkButton *button, GdkEventButton *event) void on_button3_toggled_event(GtkButton *button, GdkEventButton *event)

39
src/menu-positions.c Normal file
View File

@@ -0,0 +1,39 @@
/*
* xfce4-taskmanager - very simple taskmanger
*
* Copyright (c) 2008 Mike Massonnet <mmassonnet@xfce.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "menu-positions.h"
void position_mainmenu(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data)
{
GtkWidget *widget;
GtkRequisition requisition;
widget = user_data;
gtk_widget_size_request(GTK_WIDGET(menu), &requisition);
gdk_window_get_origin(widget->window, x, y);
*x += widget->allocation.x;
*y += widget->allocation.y;
if(*y + requisition.height > gdk_screen_height ())
*y = gdk_screen_height () - requisition.height;
else if(*y < 0)
*y = 0;
}

35
src/menu-positions.h Normal file
View File

@@ -0,0 +1,35 @@
/*
* xfce4-taskmanager - very simple taskmanger
*
* Copyright (c) 2006 Johannes Zellner, <webmaster@nebulon.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __MENU_POSITIONS_H_
#define __MENU_POSITIONS_H_
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gtk/gtk.h>
#include "functions.h"
#include "interface.h"
void position_mainmenu(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data);
#endif