Skip to content

Commit

Permalink
Add cursor property (davatorium#1313)
Browse files Browse the repository at this point in the history
* Change mouse cursor on widget hover

Currently only listview element and editbox are supported.

* Add cursor property
  • Loading branch information
TonCherAmi authored May 22, 2021
1 parent 04c006a commit dc28a97
Show file tree
Hide file tree
Showing 19 changed files with 284 additions and 9 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ addons:
- libxcb-xinerama0-dev
- libxcb-xkb-dev
- libxcb-xrm-dev
- libxcb-cursor-dev
- libxkbcommon-dev
- libxkbcommon-dev
- libxkbcommon-x11-dev
Expand Down
1 change: 1 addition & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ You can also use [Meson](https://mesonbuild.com/) as an alternative.
* xcb-util-wm (sometimes split as libxcb-ewmh and libxcb-icccm)
* xcb-util-xrm [new module might not be available in your distribution. The source can be found
here](https://github.com/Airblader/xcb-util-xrm/)
* xcb-util-cursor

On debian based systems, the developer packages are in the form of: `<package>-dev` on rpm based
`<package>-devel`.
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ NK_INIT([bindings xdg-theme])
PKG_CHECK_MODULES([glib], [glib-2.0 >= ${glib_min_version} gio-unix-2.0 gmodule-2.0])
AC_DEFINE_UNQUOTED([GLIB_VERSION_MIN_REQUIRED], [(G_ENCODE_VERSION(${glib_min_major},${glib_min_minor}))], [The lower GLib version supported])
AC_DEFINE_UNQUOTED([GLIB_VERSION_MAX_ALLOWED], [(G_ENCODE_VERSION(${glib_min_major},${glib_min_minor}))], [The highest GLib version supported])
GW_CHECK_XCB([xcb-aux xcb-xkb xkbcommon xkbcommon-x11 xcb-ewmh xcb-icccm xcb-xrm xcb-randr xcb-xinerama])
GW_CHECK_XCB([xcb-aux xcb-xkb xkbcommon xkbcommon-x11 xcb-ewmh xcb-icccm xcb-xrm xcb-cursor xcb-randr xcb-xinerama])
PKG_CHECK_MODULES([pango], [pango pangocairo])
PKG_CHECK_MODULES([cairo], [cairo cairo-xcb])
PKG_CHECK_MODULES([libsn], [libstartup-notification-1.0 ])
Expand Down
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 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 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 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
23 changes: 23 additions & 0 deletions include/xcb.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,28 @@ cairo_surface_t *x11_helper_get_screenshot_surface ( void );
*/
void x11_disable_decoration ( xcb_window_t window );

/**
* List of cursor types.
*/
typedef enum
{
/** Default arrow cursor */
CURSOR_DEFAULT = 0,
/** Cursor denoting a clickable area */
CURSOR_POINTER,
/** Cursor denoting an input field / selectable text */
CURSOR_TEXT,
NUM_CURSORS
} X11CursorType;

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

/**
* List of window managers that need different behaviour to functioning.
*/
Expand Down Expand Up @@ -212,4 +234,5 @@ cairo_surface_t *x11_helper_get_screenshot_surface_window ( xcb_window_t window,
* Blur the content of the surface with radius and deviation.
*/
void cairo_image_surface_blur(cairo_surface_t* surface, double radius, double deviation);

#endif
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
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ deps += [
dependency('xcb-icccm'),
dependency('xcb-xrm'),
dependency('xcb-randr'),
dependency('xcb-cursor'),
dependency('xcb-xinerama'),
dependency('cairo-xcb'),
dependency('libstartup-notification-1.0'),
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 dc28a97

Please sign in to comment.