2006-10-01 18:30:10 -04:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
|
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
/* Metacity resizing-terminal-window feedback */
|
|
|
|
|
2014-05-02 09:34:02 -04:00
|
|
|
/*
|
2002-03-17 12:22:23 -05:00
|
|
|
* Copyright (C) 2001 Havoc Pennington
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2002-03-17 12:22:23 -05:00
|
|
|
* 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
|
|
|
|
* General Public License for more details.
|
2014-05-02 09:34:02 -04:00
|
|
|
*
|
2002-03-17 12:22:23 -05:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-11 20:42:06 -05:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2002-03-17 12:22:23 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include "resizepopup.h"
|
2013-09-11 04:18:53 -04:00
|
|
|
#include "util-private.h"
|
2008-11-11 22:43:51 -05:00
|
|
|
#include <gtk/gtk.h>
|
2008-11-22 14:02:54 -05:00
|
|
|
#include <gdk/gdkx.h>
|
2002-03-17 12:22:23 -05:00
|
|
|
|
|
|
|
struct _MetaResizePopup
|
|
|
|
{
|
|
|
|
GtkWidget *size_window;
|
|
|
|
GtkWidget *size_label;
|
2002-10-18 18:37:01 -04:00
|
|
|
Display *display;
|
2014-05-02 09:34:02 -04:00
|
|
|
int screen_number;
|
2002-03-17 12:22:23 -05:00
|
|
|
|
|
|
|
int vertical_size;
|
|
|
|
int horizontal_size;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
gboolean showing;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2006-03-29 11:05:23 -05:00
|
|
|
MetaRectangle rect;
|
2002-03-17 12:22:23 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
MetaResizePopup*
|
2002-10-18 18:37:01 -04:00
|
|
|
meta_ui_resize_popup_new (Display *display,
|
|
|
|
int screen_number)
|
2002-03-17 12:22:23 -05:00
|
|
|
{
|
|
|
|
MetaResizePopup *popup;
|
|
|
|
|
|
|
|
popup = g_new0 (MetaResizePopup, 1);
|
|
|
|
|
2002-10-18 18:37:01 -04:00
|
|
|
popup->display = display;
|
|
|
|
popup->screen_number = screen_number;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
return popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_ui_resize_popup_free (MetaResizePopup *popup)
|
|
|
|
{
|
|
|
|
g_return_if_fail (popup != NULL);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
if (popup->size_window)
|
|
|
|
gtk_widget_destroy (popup->size_window);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
g_free (popup);
|
|
|
|
}
|
|
|
|
|
2013-01-28 16:47:47 -05:00
|
|
|
static gboolean
|
|
|
|
size_window_draw (GtkWidget *widget,
|
|
|
|
cairo_t *cr,
|
|
|
|
MetaResizePopup *popup)
|
|
|
|
{
|
|
|
|
GtkStyleContext *context;
|
|
|
|
gint width, height;
|
|
|
|
|
|
|
|
context = gtk_widget_get_style_context (widget);
|
|
|
|
width = gtk_widget_get_allocated_width (widget);
|
|
|
|
height = gtk_widget_get_allocated_height (widget);
|
|
|
|
|
|
|
|
gtk_render_background (context, cr, 0, 0, width, height);
|
|
|
|
gtk_render_frame (context, cr, 0, 0, width, height);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
static void
|
|
|
|
ensure_size_window (MetaResizePopup *popup)
|
|
|
|
{
|
2013-01-28 16:47:47 -05:00
|
|
|
GdkVisual *visual;
|
|
|
|
GdkScreen *screen;
|
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
if (popup->size_window)
|
|
|
|
return;
|
2013-01-28 16:47:47 -05:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
popup->size_window = gtk_window_new (GTK_WINDOW_POPUP);
|
2013-01-28 16:47:47 -05:00
|
|
|
screen = gdk_display_get_screen (gdk_x11_lookup_xdisplay (popup->display),
|
|
|
|
popup->screen_number);
|
|
|
|
visual = gdk_screen_get_rgba_visual (screen);
|
|
|
|
|
|
|
|
gtk_window_set_screen (GTK_WINDOW (popup->size_window), screen);
|
|
|
|
if (visual != NULL)
|
|
|
|
gtk_widget_set_visual (popup->size_window, visual);
|
|
|
|
|
|
|
|
gtk_window_set_type_hint (GTK_WINDOW (popup->size_window),
|
|
|
|
GDK_WINDOW_TYPE_HINT_TOOLTIP);
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (popup->size_window), FALSE);
|
|
|
|
|
|
|
|
gtk_widget_set_app_paintable (popup->size_window, TRUE);
|
|
|
|
gtk_style_context_add_class (gtk_widget_get_style_context (popup->size_window),
|
|
|
|
GTK_STYLE_CLASS_TOOLTIP);
|
|
|
|
g_signal_connect (popup->size_window, "draw",
|
|
|
|
G_CALLBACK (size_window_draw), popup);
|
2003-04-21 19:37:42 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
popup->size_label = gtk_label_new ("");
|
2013-01-28 16:46:14 -05:00
|
|
|
g_object_set (popup->size_label, "margin", 6, NULL);
|
2002-03-17 12:22:23 -05:00
|
|
|
|
2013-01-28 16:31:18 -05:00
|
|
|
gtk_container_add (GTK_CONTAINER (popup->size_window), popup->size_label);
|
2002-03-17 12:22:23 -05:00
|
|
|
|
2013-01-28 16:31:18 -05:00
|
|
|
gtk_widget_show (popup->size_label);
|
2002-03-17 12:22:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_size_window (MetaResizePopup *popup)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
int x, y;
|
|
|
|
int width, height;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
g_return_if_fail (popup->size_window != NULL);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
An attempt to make life a little easier for our beloved translators; this
2008-10-12 Thomas Thurman <tthurman@gnome.org>
An attempt to make life a little easier for our beloved translators;
this has the same behaviour as before, but removes over thirty
translation strings.
* src/core/session.c (start_element_handler): all "attribute not found
on element" strings are identical
* src/ui/theme-parser.c (locate_attributes): allow attribute names to
be preceded with "!" (in the code) to show they're required.
(parse_aspect_ratio, parse_distance, parse_toplevel_element,
parse_style_element, parse_gradient_element, static, parse_border,
parse_style_set_element, parse_draw_op_element): use the new "!"
prefix for locate_attributes(), or in some cases just the identical
constant, for generating this error.
* src/ui/theme.c (check_state, meta_theme_validate): add
translator comments
* src/ui/resizepopup.c (update_size_window): add
translator comments
svn path=/trunk/; revision=3949
2008-10-12 10:34:54 -04:00
|
|
|
/* Translators: This represents the size of a window. The first number is
|
|
|
|
* the width of the window and the second is the height.
|
|
|
|
*/
|
2002-03-17 12:22:23 -05:00
|
|
|
str = g_strdup_printf (_("%d x %d"),
|
|
|
|
popup->horizontal_size,
|
|
|
|
popup->vertical_size);
|
|
|
|
|
|
|
|
gtk_label_set_text (GTK_LABEL (popup->size_label), str);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
|
|
|
|
gtk_window_get_size (GTK_WINDOW (popup->size_window), &width, &height);
|
|
|
|
|
2006-03-29 11:05:23 -05:00
|
|
|
x = popup->rect.x + (popup->rect.width - width) / 2;
|
|
|
|
y = popup->rect.y + (popup->rect.height - height) / 2;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2010-04-11 14:30:44 -04:00
|
|
|
if (gtk_widget_get_realized (popup->size_window))
|
2002-03-17 12:22:23 -05:00
|
|
|
{
|
|
|
|
/* using move_resize to avoid jumpiness */
|
2010-04-11 14:30:44 -04:00
|
|
|
gdk_window_move_resize (gtk_widget_get_window (popup->size_window),
|
2002-03-17 12:22:23 -05:00
|
|
|
x, y,
|
|
|
|
width, height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_window_move (GTK_WINDOW (popup->size_window),
|
|
|
|
x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sync_showing (MetaResizePopup *popup)
|
|
|
|
{
|
|
|
|
if (popup->showing)
|
|
|
|
{
|
|
|
|
if (popup->size_window)
|
|
|
|
gtk_widget_show (popup->size_window);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2010-04-11 14:30:44 -04:00
|
|
|
if (popup->size_window && gtk_widget_get_realized (popup->size_window))
|
|
|
|
gdk_window_raise (gtk_widget_get_window (popup->size_window));
|
2002-03-17 12:22:23 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (popup->size_window)
|
|
|
|
gtk_widget_hide (popup->size_window);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_ui_resize_popup_set (MetaResizePopup *popup,
|
2006-03-29 11:05:23 -05:00
|
|
|
MetaRectangle rect,
|
2002-03-17 12:22:23 -05:00
|
|
|
int base_width,
|
|
|
|
int base_height,
|
|
|
|
int width_inc,
|
Remove the unused attributes resize_gravity, width_inc, height_inc,
2006-05-18 Björn Lindqvist <bjourne@gmail.com>
* resizepopup.c: Remove the unused attributes resize_gravity,
width_inc, height_inc, min_width, min_height, frame_left,
frame_right, frame_top, frame_bottom, tick_origin_x, tick_origin_y
from the MetaResizePopup struct. Delete all code that references
those attributes.
2006-05-18 04:32:16 -04:00
|
|
|
int height_inc)
|
2002-03-17 12:22:23 -05:00
|
|
|
{
|
|
|
|
gboolean need_update_size;
|
|
|
|
int display_w, display_h;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
g_return_if_fail (popup != NULL);
|
|
|
|
|
|
|
|
need_update_size = FALSE;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2006-03-29 11:05:23 -05:00
|
|
|
display_w = rect.width - base_width;
|
2002-03-17 12:22:23 -05:00
|
|
|
if (width_inc > 0)
|
|
|
|
display_w /= width_inc;
|
|
|
|
|
2006-03-29 11:05:23 -05:00
|
|
|
display_h = rect.height - base_height;
|
2002-03-17 12:22:23 -05:00
|
|
|
if (height_inc > 0)
|
|
|
|
display_h /= height_inc;
|
2006-03-29 11:05:23 -05:00
|
|
|
|
|
|
|
if (!meta_rectangle_equal(&popup->rect, &rect) ||
|
2002-03-17 12:22:23 -05:00
|
|
|
display_w != popup->horizontal_size ||
|
|
|
|
display_h != popup->vertical_size)
|
|
|
|
need_update_size = TRUE;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2006-03-29 11:05:23 -05:00
|
|
|
popup->rect = rect;
|
2002-03-17 12:22:23 -05:00
|
|
|
popup->vertical_size = display_h;
|
|
|
|
popup->horizontal_size = display_w;
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
if (need_update_size)
|
|
|
|
{
|
|
|
|
ensure_size_window (popup);
|
|
|
|
update_size_window (popup);
|
|
|
|
}
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
sync_showing (popup);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
meta_ui_resize_popup_set_showing (MetaResizePopup *popup,
|
|
|
|
gboolean showing)
|
|
|
|
{
|
|
|
|
g_return_if_fail (popup != NULL);
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
if (showing == popup->showing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
popup->showing = !!showing;
|
|
|
|
|
|
|
|
if (popup->showing)
|
|
|
|
{
|
|
|
|
ensure_size_window (popup);
|
|
|
|
update_size_window (popup);
|
|
|
|
}
|
2014-05-02 09:34:02 -04:00
|
|
|
|
2002-03-17 12:22:23 -05:00
|
|
|
sync_showing (popup);
|
|
|
|
}
|