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

Go to the source code of this file.

Data Structures

struct  TBFontConfig
 

Macros

#define DOT_OFFSET   15
 

Typedefs

typedef struct TBFontConfig TBFontConfig
 

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)
 
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)
 
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_icon (textbox *tb, cairo_surface_t *icon)
 
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)
 

Variables

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

Macro Definition Documentation

◆ DOT_OFFSET

#define DOT_OFFSET   15

Typedef Documentation

◆ TBFontConfig

typedef struct TBFontConfig TBFontConfig

Cache to hold font descriptions. This it to avoid having to lookup each time.

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 263 of file textbox.c.

References textbox::flags, textbox::layout, MARKUP, TB_MARKUP, TB_PASSWORD, textbox::tbft, and textbox::text.

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

Here is the caller graph for this function:

◆ _textbox_get_height()

int _textbox_get_height ( widget wid)
static

Definition at line 854 of file textbox.c.

References textbox::flags, _widget::h, TB_AUTOHEIGHT, textbox_get_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 809 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 71 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 670 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 677 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 514 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 552 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 657 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 687 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 696 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 705 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 500 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 522 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 381 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)
static

Definition at line 90 of file textbox.c.

References __textbox_update_pango_text(), textbox::changed, textbox::flags, _widget::h, TB_AUTOHEIGHT, textbox_get_height(), and textbox::widget.

Referenced by textbox_create().

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

◆ textbox_get_width()

int textbox_get_width ( widget wid)
static

Definition at line 844 of file textbox.c.

References DOT_OFFSET, textbox::flags, TB_AUTOWIDTH, TB_INDICATOR, 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 133 of file textbox.c.

References TBFontConfig::height, helper_validate_font(), textbox::layout, textbox::left_offset, TBFontConfig::metrics, textbox::metrics, p_context, p_metrics, TBFontConfig::pfd, rofi_theme_get_string(), tbfc_cache, textbox_get_estimated_char_height(), 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 85 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:

Variable Documentation

◆ ch_width

double ch_width = -1
static

Definition at line 903 of file textbox.c.

Referenced by textbox_get_estimated_ch().

◆ char_height

double char_height = -1
static

Caching for the expected character height.

Definition at line 882 of file textbox.c.

Referenced by textbox_get_estimated_char_height().

◆ char_width

double char_width = -1
static

Caching for the expected character width.

Definition at line 893 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 823 of file textbox.c.

Referenced by textbox_set_pango_context().

◆ p_context

PangoContext* p_context = NULL
static

Default pango context

Definition at line 53 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

◆ tbfc_cache

GHashTable* tbfc_cache = NULL
static

HashMap of previously parsed font descriptions.

Definition at line 69 of file textbox.c.

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

◆ 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 220 of file textbox.c.

Referenced by textbox_font().