mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Add generic container (renamed window widget) put container around message.
This commit is contained in:
parent
e6a6d5f894
commit
3eb450c37e
7 changed files with 79 additions and 84 deletions
|
@ -38,7 +38,7 @@ rofi_SOURCES=\
|
|||
source/history.c\
|
||||
source/theme.c\
|
||||
source/widgets/box.c\
|
||||
source/widgets/window.c\
|
||||
source/widgets/container.c\
|
||||
source/widgets/widget.c\
|
||||
source/widgets/textbox.c\
|
||||
source/widgets/listview.c\
|
||||
|
@ -70,7 +70,7 @@ rofi_SOURCES=\
|
|||
include/history.h\
|
||||
include/theme.h\
|
||||
include/widgets/box.h\
|
||||
include/widgets/window.h\
|
||||
include/widgets/container.h\
|
||||
include/widgets/widget.h\
|
||||
include/widgets/widget-internal.h\
|
||||
include/widgets/textbox.h\
|
||||
|
|
|
@ -34,6 +34,7 @@ List of names in **rofi**:
|
|||
* `#window.mainbox.message`
|
||||
* `#window.mainbox.message.textbox`: The message textbox.
|
||||
* `#window.mainbox.message.separator`: The separator under/above the sidebar.
|
||||
* `#window.mainbox.message.box`: The box containing the message.
|
||||
|
||||
## State
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#ifndef ROFI_VIEW_INTERNAL_H
|
||||
#define ROFI_VIEW_INTERNAL_H
|
||||
#include "widgets/window.h"
|
||||
#include "widgets/container.h"
|
||||
#include "widgets/widget.h"
|
||||
#include "widgets/textbox.h"
|
||||
#include "widgets/separator.h"
|
||||
|
@ -24,8 +24,8 @@ struct RofiViewState
|
|||
|
||||
/** Flag indicating if view needs to be refiltered. */
|
||||
int refilter;
|
||||
/** Widget representing the main window. */
|
||||
window *main_window;
|
||||
/** Widget representing the main container. */
|
||||
container *main_window;
|
||||
/** Main #box widget holding different elements. */
|
||||
box *main_box;
|
||||
/** #box widget packing the input bar widgets. */
|
||||
|
|
34
include/widgets/container.h
Normal file
34
include/widgets/container.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef ROFI_CONTAINER_H
|
||||
#define ROFI_CONTAINER_H
|
||||
|
||||
#include "widget.h"
|
||||
|
||||
/**
|
||||
* @defgroup container container
|
||||
* @ingroup widget
|
||||
*
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract handle to the container widget internal state.
|
||||
*/
|
||||
typedef struct _window container;
|
||||
|
||||
/**
|
||||
* @param name The name of the widget.
|
||||
*
|
||||
* @returns a newly created container, free with #widget_free
|
||||
*/
|
||||
container * container_create ( const char *name );
|
||||
|
||||
/**
|
||||
* @param container Handle to the container widget.
|
||||
* @param child Handle to the child widget to pack.
|
||||
*
|
||||
* Add a widget to the container.
|
||||
*/
|
||||
void container_add ( container *container, widget *child );
|
||||
/*@}*/
|
||||
#endif // ROFI_CONTAINER_H
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef ROFI_WINDOW_H
|
||||
#define ROFI_WINDOW_H
|
||||
|
||||
#include "widget.h"
|
||||
|
||||
/**
|
||||
* @defgroup window window
|
||||
* @ingroup widget
|
||||
*
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract handle to the window widget internal state.
|
||||
*/
|
||||
typedef struct _window window;
|
||||
|
||||
/**
|
||||
* @param name The name of the widget.
|
||||
*
|
||||
* @returns a newly created window, free with #widget_free
|
||||
*/
|
||||
window * window_create ( const char *name );
|
||||
|
||||
/**
|
||||
* @param window Handle to the window widget.
|
||||
* @param child Handle to the child widget to pack.
|
||||
*
|
||||
* Add a widget to the window.
|
||||
*/
|
||||
void window_add ( window *window, widget *child );
|
||||
/*@}*/
|
||||
#endif // ROFI_WINDOW_H
|
|
@ -613,7 +613,7 @@ void __create_window ( MenuFlags menu_flags )
|
|||
}
|
||||
// Setup font.
|
||||
// Dummy widget.
|
||||
window *win = window_create ( "window" );
|
||||
container *win = container_create ( "window" );
|
||||
char *font = rofi_theme_get_string ( WIDGET ( win ), "font" , config.menu_font );
|
||||
if ( font ) {
|
||||
PangoFontDescription *pfd = pango_font_description_from_string ( font );
|
||||
|
@ -1452,9 +1452,9 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
|||
// Get active monitor size.
|
||||
TICK_N ( "Get active monitor" );
|
||||
|
||||
state->main_window = window_create ( "window" );
|
||||
state->main_window = container_create ( "window" );
|
||||
state->main_box = box_create ( "window.mainbox.box", BOX_VERTICAL );
|
||||
window_add ( state->main_window, WIDGET ( state->main_box ) );
|
||||
container_add ( state->main_window, WIDGET ( state->main_box ) );
|
||||
|
||||
|
||||
state->input_bar = box_create ( "window.mainbox.inputbar.box", BOX_HORIZONTAL );
|
||||
|
@ -1495,8 +1495,10 @@ RofiViewState *rofi_view_create ( Mode *sw,
|
|||
|
||||
textbox_text ( state->case_indicator, get_matching_state () );
|
||||
if ( message ) {
|
||||
container *box = container_create ( "window.mainbox.message.box" );
|
||||
textbox *message_tb = textbox_create ( "window.mainbox.message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, message );
|
||||
box_add ( state->main_box, WIDGET ( message_tb ), FALSE, end);
|
||||
container_add ( box, WIDGET (message_tb) );
|
||||
box_add ( state->main_box, WIDGET ( box ), FALSE, end);
|
||||
}
|
||||
|
||||
state->overlay = textbox_create ( "window.overlay", TB_AUTOWIDTH|TB_AUTOHEIGHT, URGENT, "blaat" );
|
||||
|
@ -1546,9 +1548,9 @@ int rofi_view_error_dialog ( const char *msg, int markup )
|
|||
state->menu_flags = MENU_ERROR_DIALOG;
|
||||
state->finalize = process_result;
|
||||
|
||||
state->main_window = window_create ( "window" );
|
||||
state->main_window = container_create ( "window" );
|
||||
state->main_box = box_create ( "window.mainbox", BOX_VERTICAL);
|
||||
window_add ( state->main_window, WIDGET ( state->main_box ) );
|
||||
container_add ( state->main_window, WIDGET ( state->main_box ) );
|
||||
state->text = textbox_create ( "window.mainbox.message", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
|
||||
NORMAL, ( msg != NULL ) ? msg : "" );
|
||||
box_add ( state->main_box, WIDGET ( state->text ), TRUE, FALSE );
|
||||
|
|
|
@ -28,34 +28,26 @@
|
|||
#include <stdio.h>
|
||||
#include "widgets/widget.h"
|
||||
#include "widgets/widget-internal.h"
|
||||
#include "widgets/window.h"
|
||||
#include "widgets/container.h"
|
||||
#include "theme.h"
|
||||
|
||||
#define LOG_DOMAIN "Widgets.Window"
|
||||
|
||||
/** The default border width of the window */
|
||||
/** The default border width of the container */
|
||||
#define DEFAULT_BORDER_WIDTH 2
|
||||
|
||||
/**
|
||||
* @param window Handle to the window widget.
|
||||
* @param spacing The spacing to apply.
|
||||
*
|
||||
* Set the spacing to apply between the children in pixels.
|
||||
*/
|
||||
void window_set_spacing ( window * window, unsigned int spacing );
|
||||
|
||||
struct _window
|
||||
{
|
||||
widget widget;
|
||||
widget *child;
|
||||
};
|
||||
|
||||
static void window_update ( widget *wid );
|
||||
static void container_update ( widget *wid );
|
||||
|
||||
|
||||
static int window_get_desired_height ( widget *widget )
|
||||
static int container_get_desired_height ( widget *widget )
|
||||
{
|
||||
window *b = (window *) widget;
|
||||
container *b = (container *) widget;
|
||||
int height = 0;
|
||||
if ( b->child ) {
|
||||
height += widget_get_desired_height ( b->child );
|
||||
|
@ -65,34 +57,34 @@ static int window_get_desired_height ( widget *widget )
|
|||
}
|
||||
|
||||
|
||||
static void window_draw ( widget *wid, cairo_t *draw )
|
||||
static void container_draw ( widget *wid, cairo_t *draw )
|
||||
{
|
||||
window *b = (window *) wid;
|
||||
container *b = (container *) wid;
|
||||
|
||||
widget_draw ( b->child, draw );
|
||||
}
|
||||
|
||||
static void window_free ( widget *wid )
|
||||
static void container_free ( widget *wid )
|
||||
{
|
||||
window *b = (window *) wid;
|
||||
container *b = (container *) wid;
|
||||
|
||||
widget_free ( b->child );
|
||||
g_free ( b );
|
||||
}
|
||||
|
||||
void window_add ( window *window, widget *child )
|
||||
void container_add ( container *container, widget *child )
|
||||
{
|
||||
if ( window == NULL ) {
|
||||
if ( container == NULL ) {
|
||||
return;
|
||||
}
|
||||
window->child = child;
|
||||
child->parent = WIDGET ( window );
|
||||
widget_update ( WIDGET ( window ) );
|
||||
container->child = child;
|
||||
child->parent = WIDGET ( container );
|
||||
widget_update ( WIDGET ( container ) );
|
||||
}
|
||||
|
||||
static void window_resize ( widget *widget, short w, short h )
|
||||
static void container_resize ( widget *widget, short w, short h )
|
||||
{
|
||||
window *b = (window *) widget;
|
||||
container *b = (container *) widget;
|
||||
if ( b->widget.w != w || b->widget.h != h ) {
|
||||
b->widget.w = w;
|
||||
b->widget.h = h;
|
||||
|
@ -100,9 +92,9 @@ static void window_resize ( widget *widget, short w, short h )
|
|||
}
|
||||
}
|
||||
|
||||
static gboolean window_clicked ( widget *wid, xcb_button_press_event_t *xbe, G_GNUC_UNUSED void *udata )
|
||||
static gboolean container_clicked ( widget *wid, xcb_button_press_event_t *xbe, G_GNUC_UNUSED void *udata )
|
||||
{
|
||||
window *b = (window *) wid;
|
||||
container *b = (container *) wid;
|
||||
if ( widget_intersect ( b->child, xbe->event_x, xbe->event_y ) ) {
|
||||
xcb_button_press_event_t rel = *xbe;
|
||||
rel.event_x -= b->child->x;
|
||||
|
@ -111,9 +103,9 @@ static gboolean window_clicked ( widget *wid, xcb_button_press_event_t *xbe, G_G
|
|||
}
|
||||
return FALSE;
|
||||
}
|
||||
static gboolean window_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme )
|
||||
static gboolean container_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme )
|
||||
{
|
||||
window *b = (window *) wid;
|
||||
container *b = (container *) wid;
|
||||
if ( widget_intersect ( b->child, xme->event_x, xme->event_y ) ) {
|
||||
xcb_motion_notify_event_t rel = *xme;
|
||||
rel.event_x -= b->child->x;
|
||||
|
@ -123,25 +115,25 @@ static gboolean window_motion_notify ( widget *wid, xcb_motion_notify_event_t *x
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
window * window_create ( const char *name )
|
||||
container * container_create ( const char *name )
|
||||
{
|
||||
window *b = g_malloc0 ( sizeof ( window ) );
|
||||
container *b = g_malloc0 ( sizeof ( container ) );
|
||||
// Initialize widget.
|
||||
widget_init ( WIDGET(b), name );
|
||||
b->widget.draw = window_draw;
|
||||
b->widget.free = window_free;
|
||||
b->widget.resize = window_resize;
|
||||
b->widget.update = window_update;
|
||||
b->widget.clicked = window_clicked;
|
||||
b->widget.motion_notify = window_motion_notify;
|
||||
b->widget.get_desired_height = window_get_desired_height;
|
||||
b->widget.draw = container_draw;
|
||||
b->widget.free = container_free;
|
||||
b->widget.resize = container_resize;
|
||||
b->widget.update = container_update;
|
||||
b->widget.clicked = container_clicked;
|
||||
b->widget.motion_notify = container_motion_notify;
|
||||
b->widget.get_desired_height = container_get_desired_height;
|
||||
b->widget.enabled = TRUE;
|
||||
return b;
|
||||
}
|
||||
|
||||
static void window_update ( widget *wid )
|
||||
static void container_update ( widget *wid )
|
||||
{
|
||||
window *b = (window *) wid;
|
||||
container *b = (container *) wid;
|
||||
if ( b->child && b->child->enabled ){
|
||||
widget_resize ( WIDGET ( b->child ),
|
||||
widget_padding_get_remaining_width (WIDGET(b)),
|
Loading…
Reference in a new issue