Skip to content

Commit

Permalink
wnck-pager: update workspace switcher aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
raveit65 committed Nov 17, 2023
1 parent d87c912 commit 168e349
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 23 deletions.
24 changes: 15 additions & 9 deletions libmate-panel-applet/mate-panel-applet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1132,15 +1132,21 @@ mate_panel_applet_get_preferred_height (GtkWidget *widget,
static GtkSizeRequestMode
mate_panel_applet_get_request_mode (GtkWidget *widget)
{
/* Do not use GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH
* or GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT
* to avoid problems with in-process applets
* when the panel is not expanded
* See https://github.com/mate-desktop/mate-panel/issues/797
* and https://github.com/mate-desktop/mate-panel/issues/799
* Out of process applets already use GTK_SIZE_REQUEST_CONSTANT_SIZE
*/
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
MatePanelApplet *applet = MATE_PANEL_APPLET (widget);
MatePanelAppletPrivate *priv;
MatePanelAppletOrient orientation;

priv = mate_panel_applet_get_instance_private (applet);

if (priv->out_of_process)
return GTK_SIZE_REQUEST_CONSTANT_SIZE;

orientation = mate_panel_applet_get_orient (applet);
if (orientation == MATE_PANEL_APPLET_ORIENT_UP ||
orientation == MATE_PANEL_APPLET_ORIENT_DOWN)
return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH;

return GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT;
}

static void
Expand Down
103 changes: 89 additions & 14 deletions mate-panel/panel-widget.c
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,91 @@ queue_resize_on_all_applets(PanelWidget *panel)
}
}

static const gchar *applet_debug_name (AppletData *ad)
{
GtkWidget *widget = ad->applet;
static GString *gstring = NULL;

if (!gstring)
gstring = g_string_new (NULL);
else
gstring = g_string_truncate (gstring, 0);

do
{
if (gstring->len)
g_string_append (gstring, " / ");
g_string_append (gstring, gtk_widget_get_name (widget));

if (!GTK_IS_CONTAINER (widget))
widget = NULL;
else
{
GList *children = gtk_container_get_children (GTK_CONTAINER (widget));

if (!children)
widget = NULL;
else
{
widget = children->data;
g_list_free (children);
}
}
} while (widget);

return gstring->str;
}

static void
get_preferred_size (PanelWidget *self,
AppletData *ad,
GtkRequisition *minimum_size)
{
if (self->orient == GTK_ORIENTATION_HORIZONTAL)
{
if (ad->expand_minor)
minimum_size->height = self->sz;
else
gtk_widget_get_preferred_height (ad->applet,
&minimum_size->height,
NULL);

g_print ("[%s] querying width for height %d\n",
applet_debug_name (ad),
minimum_size->height);
gtk_widget_get_preferred_width_for_height (ad->applet,
minimum_size->height,
&minimum_size->width,
NULL);
}
else if (self->orient == GTK_ORIENTATION_VERTICAL)
{
if (ad->expand_minor)
minimum_size->width = self->sz;
else
gtk_widget_get_preferred_width (ad->applet,
&minimum_size->width,
NULL);

g_print ("[%s] querying height for width %d\n",
applet_debug_name (ad),
minimum_size->width);
gtk_widget_get_preferred_height_for_width (ad->applet,
minimum_size->width,
&minimum_size->height,
NULL);
}
else
{
g_assert_not_reached ();
}

g_print ("[%s] height - %d, width - %d\n",
applet_debug_name (ad),
minimum_size->height,
minimum_size->width);
}

static void
panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
Expand Down Expand Up @@ -1441,15 +1526,13 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
AppletData *ad = list->data;
GtkAllocation challoc;
GtkRequisition chreq;
gtk_widget_get_preferred_size (ad->applet, &chreq, NULL);
get_preferred_size (panel, ad, &chreq);

ad->constrained = i;

challoc.width = chreq.width;
challoc.height = chreq.height;
if(panel->orient == GTK_ORIENTATION_HORIZONTAL) {
if (ad->expand_minor)
challoc.height = allocation->height;

if (ad->expand_major && ad->size_hints) {
int width = panel->applets_using_hint[applet_using_hint_index].size;
Expand All @@ -1461,8 +1544,6 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
challoc.x = ltr ? ad->constrained : panel->size - ad->constrained - challoc.width;
challoc.y = allocation->height / 2 - challoc.height / 2;
} else {
if (ad->expand_minor)
challoc.width = allocation->width;

if (ad->expand_major && ad->size_hints) {
int height = panel->applets_using_hint[applet_using_hint_index].size;
Expand Down Expand Up @@ -1509,7 +1590,7 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
PanelObjectEdgeRelativity edge_relativity = PANEL_EDGE_START;
gboolean right_stuck = FALSE;

gtk_widget_get_preferred_size (ad->applet, &chreq, NULL);
get_preferred_size (panel, ad, &chreq);

if (!ad->expand_major || !ad->size_hints) {
if(panel->orient == GTK_ORIENTATION_HORIZONTAL)
Expand Down Expand Up @@ -1674,7 +1755,7 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
const char *id;
AppletInfo *info;
PanelObjectEdgeRelativity edge_relativity = PANEL_EDGE_START;
gboolean right_stuck;
gboolean right_stuck = FALSE;
AppletData *pad;
int prior_space;
int following_space;
Expand Down Expand Up @@ -1762,22 +1843,16 @@ panel_widget_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
AppletData *ad = list->data;
GtkAllocation challoc;
GtkRequisition chreq;
gtk_widget_get_preferred_size (ad->applet, &chreq, NULL);
get_preferred_size (panel, ad, &chreq);

challoc.width = chreq.width;
challoc.height = chreq.height;
if(panel->orient == GTK_ORIENTATION_HORIZONTAL) {
challoc.width = ad->cells;
if (ad->expand_minor) {
challoc.height = allocation->height;
}
challoc.x = ltr ? ad->constrained : panel->size - ad->constrained - challoc.width;
challoc.y = allocation->height / 2 - challoc.height / 2;
} else {
challoc.height = ad->cells;
if (ad->expand_minor) {
challoc.width = allocation->width;
}
challoc.x = allocation->width / 2 - challoc.width / 2;
challoc.y = ad->constrained;
}
Expand Down

0 comments on commit 168e349

Please sign in to comment.