Skip to content

Commit

Permalink
Add cursor property
Browse files Browse the repository at this point in the history
  • Loading branch information
TonCherAmi committed May 18, 2021
1 parent 4d0afd2 commit 9e9dd6d
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 38 deletions.
5 changes: 5 additions & 0 deletions doc/default_theme.rasi
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ element {
padding: 1px ;
spacing: 5px ;
border: 0;
cursor: pointer;
}
element normal.normal {
background-color: var(normal-background);
Expand Down Expand Up @@ -76,11 +77,13 @@ element-text {
background-color: rgba ( 0, 0, 0, 0 % );
text-color: inherit;
highlight: inherit;
cursor: inherit;
}
element-icon {
background-color: rgba ( 0, 0, 0, 0 % );
size: 1.0000em ;
text-color: inherit;
cursor: inherit;
}
window {
padding: 5;
Expand Down Expand Up @@ -121,6 +124,7 @@ sidebar {
button {
spacing: 0;
text-color: var(normal-foreground);
cursor: pointer;
}
button selected {
background-color: var(selected-normal-background);
Expand Down Expand Up @@ -151,6 +155,7 @@ entry {
text-color: var(normal-foreground);
placeholder-color: grey;
placeholder: "Type to filter";
cursor: text;
}
prompt {
spacing: 0;
Expand Down
15 changes: 15 additions & 0 deletions doc/rofi-theme.5
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ a reference
.IP \(bu 2
an orientation
.IP \(bu 2
a cursor
.IP \(bu 2
a list of keywords
.IP \(bu 2
an environment variable
Expand Down Expand Up @@ -754,6 +756,16 @@ Format: \fB\fC(horizontal|vertical)\fR
.PP
Specify the orientation of the widget.

.SH Cursor
.RS
.IP \(bu 2
Format: \fB\fC(default|pointer|text)\fR

.RE

.PP
Specify the type of mouse cursor that is set when the mouse pointer is hovered over the widget.

.SH List of keywords
.RS
.IP \(bu 2
Expand Down Expand Up @@ -1012,6 +1024,9 @@ Background color
.IP \(bu 2
\fBborder\-color\fP: color
Color of the border
.IP \(bu 2
\fBcursor\fP: cursor
Type of mouse cursor that is set when the mouse pointer is hovered over the widget.

.RE

Expand Down
9 changes: 9 additions & 0 deletions doc/rofi-theme.5.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ The current theme format supports different types:
* a position
* a reference
* an orientation
* a cursor
* a list of keywords
* an environment variable
* Inherit
Expand Down Expand Up @@ -462,6 +463,12 @@ window {

Specify the orientation of the widget.

## Cursor

* Format: `(default|pointer|text)`

Specify the type of mouse cursor that is set when the mouse pointer is hovered over the widget.

## List of keywords

* Format: `[ keyword, keyword ]`
Expand Down Expand Up @@ -620,6 +627,8 @@ The following properties are currently supported:
Background color
* **border-color**: color
Color of the border
* **cursor**: cursor
Type of mouse cursor that is set when the mouse pointer is hovered over the widget.

### window:

Expand Down
12 changes: 12 additions & 0 deletions include/rofi-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ typedef enum
P_LIST,
/** Orientation */
P_ORIENTATION,
/** Cursor */
P_CURSOR,
/** Inherit */
P_INHERIT,
/** Number of types. */
Expand Down Expand Up @@ -140,6 +142,16 @@ typedef enum
ROFI_ORIENTATION_HORIZONTAL
} RofiOrientation;

/**
* Cursor type.
*/
typedef enum
{
ROFI_CURSOR_DEFAULT,
ROFI_CURSOR_POINTER,
ROFI_CURSOR_TEXT
} RofiCursorType;

/**
* Represent the color in theme.
*/
Expand Down
11 changes: 11 additions & 0 deletions include/theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,17 @@ int rofi_theme_get_boolean ( const widget *widget, const char *property, int
* @returns The orientation of this property for this widget or %def not found.
*/
RofiOrientation rofi_theme_get_orientation ( const widget *widget, const char *property, RofiOrientation def );

/**
* @param widget The widget to query
* @param property The property to query.
* @param def The default value.
*
* Obtain the cursor indicated by %property of the widget.
*
* @returns The cursor of for this widget or %def if not found.
*/
RofiCursorType rofi_theme_get_cursor_type ( const widget *widget, const char *property, RofiCursorType def );
/**
* @param widget The widget to query
* @param property The property to query.
Expand Down
3 changes: 3 additions & 0 deletions include/widgets/widget-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ struct _widget
RofiPadding border;
RofiPadding border_radius;

/** Cursor that is set when the widget is hovered */
RofiCursorType cursor_type;

/** enabled or not */
gboolean enabled;
/** Expand the widget when packed */
Expand Down
4 changes: 2 additions & 2 deletions include/xcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,15 @@ typedef enum
/** Cursor denoting an input field / selectable text */
CURSOR_TEXT,
NUM_CURSORS
} CursorType;
} X11CursorType;

/**
* @param window
* @param type
*
* Change mouse cursor
*/
void x11_set_cursor( xcb_window_t window, CursorType type );
void x11_set_cursor ( xcb_window_t window, X11CursorType type );

/**
* List of window managers that need different behaviour to functioning.
Expand Down
10 changes: 10 additions & 0 deletions lexer/theme-lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ LS_SOLID (?i:solid)
ORIENTATION_HORI (?i:horizontal)
ORIENTATION_VERT (?i:vertical)
/* Cursor */
CURSOR_DEF (?i:default)
CURSOR_PTR (?i:pointer)
CURSOR_TXT (?i:text)
/* Color schema */
RGBA (?i:rgb[a]?)
HWB (?i:hwb)
Expand Down Expand Up @@ -598,6 +604,10 @@ if ( queue == NULL ){
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ORIENTATION_HORI} { return ORIENTATION_HORI; }
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{ORIENTATION_VERT} { return ORIENTATION_VERT; }

<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CURSOR_DEF} { return CURSOR_DEF; }
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CURSOR_PTR} { return CURSOR_PTR; }
<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{CURSOR_TXT} { return CURSOR_TXT; }

<PROPERTIES,PROPERTIES_ENV,PROPERTIES_VAR_DEFAULT>{COLOR_TRANSPARENT} {
return T_COLOR_TRANSPARENT;
}
Expand Down
15 changes: 15 additions & 0 deletions lexer/theme-parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%token ORIENTATION_HORI "Horizontal"
%token ORIENTATION_VERT "Vertical"

%token CURSOR_DEF "Default"
%token CURSOR_PTR "Pointer"
%token CURSOR_TXT "Text"

%token T_COL_RGBA "rgb[a] colorscheme"
%token T_COL_HSL "hsl colorscheme"
%token T_COL_HWB "hwb colorscheme"
Expand Down Expand Up @@ -276,6 +280,7 @@ static ThemeColor hwb_to_rgb ( double h, double w, double b)
%type <list> t_property_element_list
%type <list> t_property_element_list_optional
%type <ival> t_property_orientation
%type <ival> t_property_cursor
%type <ival> t_name_prefix_optional
%start t_main

Expand Down Expand Up @@ -512,6 +517,10 @@ t_property_element
$$ = rofi_theme_property_create ( P_ORIENTATION );
$$->value.i = $1;
}
| t_property_cursor {
$$ = rofi_theme_property_create ( P_CURSOR );
$$->value.i = $1;
}
;

/** List of elements */
Expand Down Expand Up @@ -846,6 +855,12 @@ t_property_orientation
| ORIENTATION_VERT { $$ = ROFI_ORIENTATION_VERTICAL; }
;

t_property_cursor
: CURSOR_DEF { $$ = ROFI_CURSOR_DEFAULT; }
| CURSOR_PTR { $$ = ROFI_CURSOR_POINTER; }
| CURSOR_TXT { $$ = ROFI_CURSOR_TEXT; }
;

/** Property name */
t_property_name
: T_PROP_NAME { $$ = $1; }
Expand Down
2 changes: 2 additions & 0 deletions source/rofi-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const char * const PropertyTypeName[P_NUM_TYPES] = {
"List",
/** Orientation */
"Orientation",
/** Cursor */
"Cursor",
/** Inherit */
"Inherit",
};
26 changes: 26 additions & 0 deletions source/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ const char * const WindowLocationStr[9] = {
"west"
};

/** Textual representation of RofiCursorType */
const char *const RofiCursorTypeStr[3] = {
"default",
"pointer",
"text",
};

static void int_rofi_theme_print_property ( Property *p )
{
switch ( p->type )
Expand All @@ -376,6 +383,9 @@ static void int_rofi_theme_print_property ( Property *p )
case P_ORIENTATION:
printf ( "%s", ( p->value.i == ROFI_ORIENTATION_HORIZONTAL ) ? "horizontal" : "vertical" );
break;
case P_CURSOR:
printf ( "%s", RofiCursorTypeStr[p->value.i] );
break;
case P_HIGHLIGHT:
if ( p->value.highlight.style & ROFI_HL_BOLD ) {
printf ( "bold " );
Expand Down Expand Up @@ -814,6 +824,22 @@ RofiOrientation rofi_theme_get_orientation ( const widget *widget, const char *p
g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def;
}
RofiCursorType rofi_theme_get_cursor_type ( const widget *widget, const char *property, RofiCursorType def )
{
ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE );
Property *p = rofi_theme_find_property ( wid, P_CURSOR, property, FALSE );
if ( p ) {
if ( p->type == P_INHERIT ) {
if ( widget->parent ) {
return rofi_theme_get_cursor_type ( widget->parent, property, def );
}
return def;
}
return p->value.i;
}
g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property );
return def;
}

const char *rofi_theme_get_string ( const widget *widget, const char *property, const char *def )
{
Expand Down
Loading

0 comments on commit 9e9dd6d

Please sign in to comment.