rofi 1.7.5
textbox.c File Reference
#include "widgets/textbox.h"
#include "helper-theme.h"
#include "helper.h"
#include "keyb.h"
#include "mode.h"
#include "view.h"
#include <ctype.h>
#include <glib.h>
#include <math.h>
#include <string.h>
#include <xcb/xcb.h>
#include "theme.h"
Include dependency graph for textbox.c:

Go to the source code of this file.

Functions

static void textbox_draw (widget *, cairo_t *)
 
static void textbox_free (widget *)
 
static int textbox_get_width (widget *)
 
static int _textbox_get_height (widget *)
 
static void __textbox_update_pango_text (textbox *tb)
 
static gboolean textbox_blink (gpointer data)
 
static void textbox_resize (widget *wid, short w, short h)
 
static int textbox_get_desired_height (widget *wid, const int width)
 
static WidgetTriggerActionResult textbox_editable_trigger_action (widget *wid, MouseBindingMouseDefaultAction action, gint x, gint y, G_GNUC_UNUSED void *user_data)
 
static void textbox_initialize_font (textbox *tb)
 
static void textbox_tab_stops (textbox *tb)
 
textboxtextbox_create (widget *parent, WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign)
 
void textbox_font (textbox *tb, TextBoxFontType tbft)
 
const char * textbox_get_visible_text (const textbox *tb)
 
PangoAttrList * textbox_get_pango_attributes (textbox *tb)
 
void textbox_set_pango_attributes (textbox *tb, PangoAttrList *list)
 
void textbox_text (textbox *tb, const char *text)
 
void textbox_moveresize (textbox *tb, int x, int y, int w, int h)
 
void textbox_cursor (textbox *tb, int pos)
 
static int textbox_cursor_inc (textbox *tb)
 
static int textbox_cursor_dec (textbox *tb)
 
static void textbox_cursor_inc_word (textbox *tb)
 
static void textbox_cursor_dec_word (textbox *tb)
 
void textbox_cursor_end (textbox *tb)
 
void textbox_insert (textbox *tb, const int char_pos, const char *str, const int slen)
 
void textbox_delete (textbox *tb, int pos, int dlen)
 
static void textbox_cursor_del (textbox *tb)
 
static void textbox_cursor_bkspc (textbox *tb)
 
static void textbox_cursor_bkspc_word (textbox *tb)
 
static void textbox_cursor_del_eol (textbox *tb)
 
static void textbox_cursor_del_sol (textbox *tb)
 
static void textbox_cursor_del_word (textbox *tb)
 
int textbox_keybinding (textbox *tb, KeyBindingAction action)
 
gboolean textbox_append_text (textbox *tb, const char *pad, const int pad_len)
 
static void tbfc_entry_free (TBFontConfig *tbfc)
 
void textbox_setup (void)
 
void textbox_set_pango_context (const char *font, PangoContext *p)
 
void textbox_cleanup (void)
 
int textbox_get_height (const textbox *tb)
 
int textbox_get_font_height (const textbox *tb)
 
int textbox_get_font_width (const textbox *tb)
 
double textbox_get_estimated_char_height (void)
 
double textbox_get_estimated_char_width (void)
 
double textbox_get_estimated_ch (void)
 
int textbox_get_estimated_height (const textbox *tb, int eh)
 
int textbox_get_desired_width (widget *wid, G_GNUC_UNUSED const int height)
 
void textbox_set_ellipsize (textbox *tb, PangoEllipsizeMode mode)
 

Variables

static PangoContext * p_context = NULL
 
static PangoFontMetrics * p_metrics = NULL
 
static TBFontConfigtbfc_default = NULL
 
static GHashTable * tbfc_cache = NULL
 
const char *const theme_prop_names [][3]
 
const char * default_font_name = "default"
 
static double char_width = -1
 
static double ch_width = -1
 

Function Documentation

◆ __textbox_update_pango_text()

static void __textbox_update_pango_text ( textbox * tb)
static
Parameters
tbThe textbox object.

Update the pango layout's text. It does this depending on the textbox flags.

Definition at line 309 of file textbox.c.

References textbox::flags, helper_token_match_set_pango_attr_on_style(), textbox::layout, MARKUP, textbox::placeholder, rofi_theme_get_highlight(), textbox::show_placeholder, RofiHighlightColorStyle::style, TB_MARKUP, TB_PASSWORD, textbox::tbft, textbox::text, and WIDGET.

Referenced by textbox_draw(), textbox_get_desired_height(), and textbox_text().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _textbox_get_height()

int _textbox_get_height ( widget * wid)
static

Definition at line 906 of file textbox.c.

References textbox::flags, _widget::h, textbox::layout, TB_AUTOHEIGHT, textbox_get_estimated_height(), and textbox::widget.

Referenced by textbox_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tbfc_entry_free()

static void tbfc_entry_free ( TBFontConfig * tbfc)
static

Definition at line 857 of file textbox.c.

References TBFontConfig::metrics, and TBFontConfig::pfd.

Referenced by textbox_setup().

Here is the caller graph for this function:

◆ textbox_blink()

static gboolean textbox_blink ( gpointer data)
static

Definition at line 60 of file textbox.c.

References textbox::blink, rofi_view_queue_redraw(), WIDGET, and widget_queue_redraw().

Referenced by textbox_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_bkspc()

static void textbox_cursor_bkspc ( textbox * tb)
static
Parameters
tbHandle to the textbox

Delete character before cursor.

Definition at line 727 of file textbox.c.

References textbox::cursor, textbox_cursor_dec(), and textbox_cursor_del().

Referenced by textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_bkspc_word()

static void textbox_cursor_bkspc_word ( textbox * tb)
static

Definition at line 733 of file textbox.c.

References textbox::cursor, textbox_cursor_dec_word(), and textbox_delete().

Referenced by textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_dec()

static int textbox_cursor_dec ( textbox * tb)
static
Parameters
tbHandle to the textbox

Move cursor one position backward.

Returns
if cursor was moved.

Definition at line 574 of file textbox.c.

References textbox::cursor, and textbox_cursor().

Referenced by textbox_cursor_bkspc(), and textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_dec_word()

static void textbox_cursor_dec_word ( textbox * tb)
static

Definition at line 612 of file textbox.c.

References textbox::cursor, textbox::text, and textbox_cursor().

Referenced by textbox_cursor_bkspc_word(), and textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_del()

static void textbox_cursor_del ( textbox * tb)
static
Parameters
tbHandle to the textbox

Delete character after cursor.

Definition at line 715 of file textbox.c.

References textbox::cursor, textbox::text, and textbox_delete().

Referenced by textbox_cursor_bkspc(), and textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_del_eol()

static void textbox_cursor_del_eol ( textbox * tb)
static

Definition at line 742 of file textbox.c.

References textbox::cursor, textbox::text, and textbox_delete().

Referenced by textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_del_sol()

static void textbox_cursor_del_sol ( textbox * tb)
static

Definition at line 750 of file textbox.c.

References textbox::cursor, and textbox_delete().

Referenced by textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_del_word()

static void textbox_cursor_del_word ( textbox * tb)
static

Definition at line 756 of file textbox.c.

References textbox::cursor, textbox_cursor_inc_word(), and textbox_delete().

Referenced by textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_inc()

static int textbox_cursor_inc ( textbox * tb)
static
Parameters
tbHandle to the textbox

Move cursor one position forward.

Returns
if cursor was moved.

Definition at line 561 of file textbox.c.

References textbox::cursor, and textbox_cursor().

Referenced by textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_cursor_inc_word()

static void textbox_cursor_inc_word ( textbox * tb)
static

Definition at line 581 of file textbox.c.

References textbox::cursor, textbox::text, and textbox_cursor().

Referenced by textbox_cursor_del_word(), and textbox_keybinding().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_draw()

◆ textbox_editable_trigger_action()

static WidgetTriggerActionResult textbox_editable_trigger_action ( widget * wid,
MouseBindingMouseDefaultAction action,
gint x,
gint y,
G_GNUC_UNUSED void * user_data )
static

◆ textbox_free()

static void textbox_free ( widget * wid)
static

Definition at line 434 of file textbox.c.

References textbox::blink_timeout, textbox::layout, and textbox::text.

Referenced by textbox_create().

Here is the caller graph for this function:

◆ textbox_get_desired_height()

static int textbox_get_desired_height ( widget * wid,
const int width )
static

Definition at line 76 of file textbox.c.

References __textbox_update_pango_text(), textbox::changed, textbox::flags, _widget::h, textbox::layout, TB_AUTOHEIGHT, textbox_get_estimated_height(), WIDGET, textbox::widget, and widget_padding_get_padding_width().

Referenced by textbox_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_get_desired_width()

int textbox_get_desired_width ( widget * wid,
G_GNUC_UNUSED const int height )

◆ textbox_get_width()

int textbox_get_width ( widget * wid)
static

Definition at line 898 of file textbox.c.

References textbox::flags, TB_AUTOWIDTH, textbox_get_font_width(), _widget::w, textbox::widget, and widget_padding_get_padding_width().

Referenced by textbox_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_initialize_font()

static void textbox_initialize_font ( textbox * tb)
static

Definition at line 125 of file textbox.c.

References TBFontConfig::height, helper_validate_font(), textbox::layout, TBFontConfig::metrics, p_context, TBFontConfig::pfd, rofi_theme_get_string(), textbox::tbfc, tbfc_cache, tbfc_default, and WIDGET.

Referenced by textbox_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_resize()

static void textbox_resize ( widget * wid,
short w,
short h )
static

Definition at line 72 of file textbox.c.

References textbox_moveresize(), textbox::widget, _widget::x, and _widget::y.

Referenced by textbox_create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ textbox_tab_stops()

static void textbox_tab_stops ( textbox * tb)
static

Definition at line 161 of file textbox.c.

References distance_get_pixel(), textbox::layout, ROFI_ORIENTATION_HORIZONTAL, rofi_theme_get_list_distance(), and WIDGET.

Referenced by textbox_create().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ ch_width

double ch_width = -1
static

Cache storing the estimated width of a digit (ch).

Definition at line 945 of file textbox.c.

Referenced by textbox_get_estimated_ch().

◆ char_width

double char_width = -1
static

Caching for the expected character width.

Definition at line 935 of file textbox.c.

Referenced by textbox_get_estimated_char_width().

◆ default_font_name

const char* default_font_name = "default"

Name of the default font (if none is given)

Definition at line 870 of file textbox.c.

Referenced by textbox_set_pango_context().

◆ p_context

PangoContext* p_context = NULL
static

Default pango context

Definition at line 50 of file textbox.c.

Referenced by textbox_cleanup(), textbox_create(), textbox_initialize_font(), and textbox_set_pango_context().

◆ p_metrics

PangoFontMetrics* p_metrics = NULL
static

The pango font metrics

Definition at line 52 of file textbox.c.

Referenced by textbox_get_estimated_ch(), textbox_get_estimated_char_width(), and textbox_set_pango_context().

◆ tbfc_cache

GHashTable* tbfc_cache = NULL
static

HashMap of previously parsed font descriptions.

Definition at line 58 of file textbox.c.

Referenced by textbox_cleanup(), textbox_initialize_font(), textbox_set_pango_context(), and textbox_setup().

◆ tbfc_default

TBFontConfig* tbfc_default = NULL
static

Default tbfc

Definition at line 55 of file textbox.c.

Referenced by textbox_get_estimated_char_height(), textbox_initialize_font(), and textbox_set_pango_context().

◆ theme_prop_names

const char* const theme_prop_names[][3]
Initial value:
= {
{"normal.normal", "selected.normal", "alternate.normal"},
{"normal.urgent", "selected.urgent", "alternate.urgent"},
{"normal.active", "selected.active", "alternate.active"},
}

State names used for theming.

Definition at line 268 of file textbox.c.

Referenced by textbox_font().