mirror of
https://github.com/davatorium/rofi.git
synced 2025-07-31 21:59:25 -04:00
Fix some of the sizing issues.
This commit is contained in:
parent
04ad719c01
commit
eafd4697a2
7 changed files with 107 additions and 56 deletions
|
@ -41,6 +41,8 @@ struct _widget
|
||||||
/** Handle mouse motion, used for dragging */
|
/** Handle mouse motion, used for dragging */
|
||||||
gboolean ( *motion_notify )( struct _widget *, xcb_motion_notify_event_t * );
|
gboolean ( *motion_notify )( struct _widget *, xcb_motion_notify_event_t * );
|
||||||
|
|
||||||
|
int (*get_desired_height) ( struct _widget * );
|
||||||
|
|
||||||
/** widget clicked callback */
|
/** widget clicked callback */
|
||||||
widget_clicked_cb clicked;
|
widget_clicked_cb clicked;
|
||||||
/** user data for clicked callback */
|
/** user data for clicked callback */
|
||||||
|
|
|
@ -176,5 +176,6 @@ gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
|
||||||
|
|
||||||
|
|
||||||
void widget_set_name ( widget *wid, const char *name );
|
void widget_set_name ( widget *wid, const char *name );
|
||||||
|
int widget_get_desired_height ( widget *wid );
|
||||||
/*@}*/
|
/*@}*/
|
||||||
#endif // ROFI_WIDGET_H
|
#endif // ROFI_WIDGET_H
|
||||||
|
|
|
@ -1361,26 +1361,10 @@ static int rofi_view_calculate_height ( RofiViewState *state )
|
||||||
widget_enable ( WIDGET ( state->input_bar_separator ) );
|
widget_enable ( WIDGET ( state->input_bar_separator ) );
|
||||||
widget_enable ( WIDGET ( state->list_view) );
|
widget_enable ( WIDGET ( state->list_view) );
|
||||||
}
|
}
|
||||||
height = listview_get_desired_height ( state->list_view );
|
|
||||||
// Why not a factor 2 here?
|
|
||||||
height += window_get_border_width ( state->main_window );
|
|
||||||
height += box_get_fixed_pixels ( state->main_box );
|
|
||||||
// How to merge this....
|
|
||||||
int perc =0;
|
|
||||||
widget *main_window = WIDGET ( state->main_window );
|
widget *main_window = WIDGET ( state->main_window );
|
||||||
if ( main_window->pad.top >= 0 ){
|
height = widget_get_desired_height ( main_window );
|
||||||
height += main_window->pad.top;
|
|
||||||
} else {
|
|
||||||
perc -= main_window->pad.top;
|
|
||||||
}
|
|
||||||
if ( main_window->pad.bottom >= 0 ){
|
|
||||||
height += main_window->pad.bottom;
|
|
||||||
} else {
|
|
||||||
perc -= main_window->pad.bottom;
|
|
||||||
}
|
|
||||||
if ( perc > 0){
|
|
||||||
height = (100*height)/(100-perc);
|
|
||||||
}
|
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,43 @@ struct _box
|
||||||
|
|
||||||
static void box_update ( widget *wid );
|
static void box_update ( widget *wid );
|
||||||
|
|
||||||
|
static int box_get_desired_height ( widget *wid )
|
||||||
|
{
|
||||||
|
box *b = (box *)wid;
|
||||||
|
int active_widgets = 0;
|
||||||
|
int height = widget_padding_get_padding_height ( wid );
|
||||||
|
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||||
|
widget * child = (widget *) iter->data;
|
||||||
|
if ( !child->enabled ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
active_widgets++;
|
||||||
|
if ( child->expand == TRUE ) {
|
||||||
|
height += widget_get_desired_height ( child );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
height += child->h;
|
||||||
|
}
|
||||||
|
if ( active_widgets > 0 ){
|
||||||
|
height += (active_widgets - 1)*b->spacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void vert_calculate_size ( box *b )
|
static void vert_calculate_size ( box *b )
|
||||||
{
|
{
|
||||||
int expanding_widgets = 0;
|
int expanding_widgets = 0;
|
||||||
int active_widgets = 0;
|
int active_widgets = 0;
|
||||||
|
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) );
|
||||||
|
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) );
|
||||||
|
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||||
|
widget * child = (widget *) iter->data;
|
||||||
|
if ( child->enabled && child->expand == FALSE ){
|
||||||
|
widget_resize ( child, rem_width, child->h );
|
||||||
|
}
|
||||||
|
}
|
||||||
b->max_size = 0;
|
b->max_size = 0;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||||
widget * child = (widget *) iter->data;
|
widget * child = (widget *) iter->data;
|
||||||
|
@ -71,14 +104,15 @@ static void vert_calculate_size ( box *b )
|
||||||
expanding_widgets++;
|
expanding_widgets++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if ( child->h > 0 ){
|
||||||
b->max_size += child->h;
|
b->max_size += child->h;
|
||||||
}
|
}
|
||||||
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) );
|
}
|
||||||
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) );
|
|
||||||
if ( active_widgets > 0 ){
|
if ( active_widgets > 0 ){
|
||||||
b->max_size += ( active_widgets - 1 ) * b->spacing;
|
b->max_size += ( active_widgets - 1 ) * b->spacing;
|
||||||
}
|
}
|
||||||
if ( b->max_size > rem_height ) {
|
if ( b->max_size > rem_height ) {
|
||||||
|
b->max_size = rem_height;
|
||||||
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (height) for box: %d %d", b->max_size, b->widget.h );
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (height) for box: %d %d", b->max_size, b->widget.h );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -109,18 +143,16 @@ static void vert_calculate_size ( box *b )
|
||||||
}
|
}
|
||||||
rem -= expanding_widgets_size;
|
rem -= expanding_widgets_size;
|
||||||
index++;
|
index++;
|
||||||
b->max_size += widget_padding_get_padding_height ( child);
|
// b->max_size += widget_padding_get_padding_height ( child);
|
||||||
}
|
}
|
||||||
else if ( child->end ) {
|
else if ( child->end ) {
|
||||||
bottom -= widget_get_height ( child );
|
bottom -= widget_get_height ( child );
|
||||||
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), bottom );
|
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), bottom );
|
||||||
widget_resize ( child, rem_width, child->h );
|
|
||||||
bottom -= b->spacing;
|
bottom -= b->spacing;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top );
|
widget_move ( child, widget_padding_get_left ( WIDGET ( b ) ), top );
|
||||||
top += widget_get_height ( child );
|
top += widget_get_height ( child );
|
||||||
widget_resize ( child, rem_width, child->h );
|
|
||||||
top += b->spacing;
|
top += b->spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -131,6 +163,14 @@ static void hori_calculate_size ( box *b )
|
||||||
{
|
{
|
||||||
int expanding_widgets = 0;
|
int expanding_widgets = 0;
|
||||||
int active_widgets = 0;
|
int active_widgets = 0;
|
||||||
|
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) );
|
||||||
|
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) );
|
||||||
|
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||||
|
widget * child = (widget *) iter->data;
|
||||||
|
if ( child->enabled && child->expand == FALSE ){
|
||||||
|
widget_resize ( child, child->w, rem_height );
|
||||||
|
}
|
||||||
|
}
|
||||||
b->max_size = 0;
|
b->max_size = 0;
|
||||||
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
|
||||||
widget * child = (widget *) iter->data;
|
widget * child = (widget *) iter->data;
|
||||||
|
@ -143,12 +183,13 @@ static void hori_calculate_size ( box *b )
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Size used by fixed width widgets.
|
// Size used by fixed width widgets.
|
||||||
|
if ( child->h > 0 ){
|
||||||
b->max_size += child->w;
|
b->max_size += child->w;
|
||||||
}
|
}
|
||||||
int rem_width = widget_padding_get_remaining_width ( WIDGET (b) );
|
}
|
||||||
int rem_height = widget_padding_get_remaining_height ( WIDGET (b) );
|
|
||||||
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->spacing ) );
|
b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->spacing ) );
|
||||||
if ( b->max_size > (rem_width)) {
|
if ( b->max_size > (rem_width)) {
|
||||||
|
b->max_size = rem_width;
|
||||||
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (width) for box: %d %d", b->max_size, b->widget.w );
|
g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (width) for box: %d %d", b->max_size, b->widget.w );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -179,18 +220,16 @@ static void hori_calculate_size ( box *b )
|
||||||
}
|
}
|
||||||
rem -= expanding_widgets_size;
|
rem -= expanding_widgets_size;
|
||||||
index++;
|
index++;
|
||||||
b->max_size += widget_padding_get_padding_width ( child);
|
// b->max_size += widget_padding_get_padding_width ( child);
|
||||||
}
|
}
|
||||||
else if ( child->end ) {
|
else if ( child->end ) {
|
||||||
right -= widget_get_width ( child );
|
right -= widget_get_width ( child );
|
||||||
widget_move ( child, right, widget_padding_get_top ( WIDGET ( b ) ) );
|
widget_move ( child, right, widget_padding_get_top ( WIDGET ( b ) ) );
|
||||||
widget_resize ( child, child->w, rem_height );
|
|
||||||
right -= b->spacing;
|
right -= b->spacing;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) );
|
widget_move ( child, left, widget_padding_get_top ( WIDGET ( b ) ) );
|
||||||
left += widget_get_width ( child );
|
left += widget_get_width ( child );
|
||||||
widget_resize ( child, child->w, rem_height );
|
|
||||||
left += b->spacing;
|
left += b->spacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,6 +337,7 @@ box * box_create ( const char *name, boxType type )
|
||||||
b->widget.update = box_update;
|
b->widget.update = box_update;
|
||||||
b->widget.clicked = box_clicked;
|
b->widget.clicked = box_clicked;
|
||||||
b->widget.motion_notify = box_motion_notify;
|
b->widget.motion_notify = box_motion_notify;
|
||||||
|
b->widget.get_desired_height = box_get_desired_height;
|
||||||
b->widget.enabled = TRUE;
|
b->widget.enabled = TRUE;
|
||||||
|
|
||||||
box_set_spacing ( b, rofi_theme_get_integer ( b->widget.class_name, b->widget.name, NULL, "spacing",config.line_margin ));
|
box_set_spacing ( b, rofi_theme_get_integer ( b->widget.class_name, b->widget.name, NULL, "spacing",config.line_margin ));
|
||||||
|
@ -320,6 +360,7 @@ static void box_update ( widget *wid )
|
||||||
int box_get_fixed_pixels ( box *box )
|
int box_get_fixed_pixels ( box *box )
|
||||||
{
|
{
|
||||||
if ( box != NULL ) {
|
if ( box != NULL ) {
|
||||||
|
printf("max size: %d\n", box->max_size);
|
||||||
return box->max_size;
|
return box->max_size;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -327,6 +327,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
|
||||||
lv->widget.draw = listview_draw;
|
lv->widget.draw = listview_draw;
|
||||||
lv->widget.clicked = listview_clicked;
|
lv->widget.clicked = listview_clicked;
|
||||||
lv->widget.motion_notify = listview_motion_notify;
|
lv->widget.motion_notify = listview_motion_notify;
|
||||||
|
lv->widget.get_desired_height = listview_get_desired_height;
|
||||||
lv->widget.enabled = TRUE;
|
lv->widget.enabled = TRUE;
|
||||||
lv->eh = eh;
|
lv->eh = eh;
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,10 @@ void widget_resize ( widget *widget, short w, short h )
|
||||||
{
|
{
|
||||||
if ( widget != NULL ) {
|
if ( widget != NULL ) {
|
||||||
if ( widget->resize != NULL ) {
|
if ( widget->resize != NULL ) {
|
||||||
|
if ( widget->w != w || widget->h != h ) {
|
||||||
widget->resize ( widget, w, h );
|
widget->resize ( widget, w, h );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
widget->w = w;
|
widget->w = w;
|
||||||
widget->h = h;
|
widget->h = h;
|
||||||
|
@ -151,8 +153,6 @@ void widget_update ( widget *widget )
|
||||||
if ( widget->update ) {
|
if ( widget->update ) {
|
||||||
widget->update ( widget );
|
widget->update ( widget );
|
||||||
}
|
}
|
||||||
// Recurse back.
|
|
||||||
widget_update ( widget->parent );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -265,3 +265,13 @@ int widget_padding_get_padding_width ( const widget *wid )
|
||||||
width += widget_padding_get_right ( wid );
|
width += widget_padding_get_right ( wid );
|
||||||
return width;
|
return width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int widget_get_desired_height ( widget *wid )
|
||||||
|
{
|
||||||
|
if ( wid->get_desired_height )
|
||||||
|
{
|
||||||
|
return wid->get_desired_height ( wid );
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -53,6 +53,17 @@ struct _window
|
||||||
static void window_update ( widget *wid );
|
static void window_update ( widget *wid );
|
||||||
|
|
||||||
|
|
||||||
|
static int window_get_desired_height ( widget *widget )
|
||||||
|
{
|
||||||
|
window *b = (window *) widget;
|
||||||
|
int height = b->border_width*2;
|
||||||
|
if ( b->child ) {
|
||||||
|
height += widget_get_desired_height ( b->child );
|
||||||
|
}
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void window_draw ( widget *wid, cairo_t *draw )
|
static void window_draw ( widget *wid, cairo_t *draw )
|
||||||
{
|
{
|
||||||
window *b = (window *) wid;
|
window *b = (window *) wid;
|
||||||
|
@ -132,6 +143,7 @@ window * window_create ( const char *name )
|
||||||
b->widget.update = window_update;
|
b->widget.update = window_update;
|
||||||
b->widget.clicked = window_clicked;
|
b->widget.clicked = window_clicked;
|
||||||
b->widget.motion_notify = window_motion_notify;
|
b->widget.motion_notify = window_motion_notify;
|
||||||
|
b->widget.get_desired_height = window_get_desired_height;
|
||||||
b->widget.enabled = TRUE;
|
b->widget.enabled = TRUE;
|
||||||
b->border_width = rofi_theme_get_integer (
|
b->border_width = rofi_theme_get_integer (
|
||||||
b->widget.class_name, b->widget.name, NULL, "border-width" , config.menu_bw);
|
b->widget.class_name, b->widget.name, NULL, "border-width" , config.menu_bw);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue