2016-10-08 16:57:59 +00:00
|
|
|
/**
|
|
|
|
* MIT/X11 License
|
|
|
|
* Modified (c) 2016 Qball Cow <qball@gmpclient.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <xkbcommon/xkbcommon.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
2016-10-09 08:13:15 +00:00
|
|
|
#include "widgets/widget.h"
|
|
|
|
#include "widgets/widget-internal.h"
|
2016-10-08 16:57:59 +00:00
|
|
|
#include "widgets/separator.h"
|
|
|
|
#include "x11-helper.h"
|
|
|
|
#include "settings.h"
|
2016-12-11 11:19:46 +00:00
|
|
|
#include "theme.h"
|
|
|
|
|
2016-12-27 21:19:15 +00:00
|
|
|
const char *SEPARATOR_CLASS_NAME = "@separator";
|
2016-12-11 11:19:46 +00:00
|
|
|
/**
|
|
|
|
* @param sp The separator widget handle.
|
|
|
|
* @param style_str String representation of the style.
|
|
|
|
*
|
|
|
|
* Sets the line style based on the string style_str
|
|
|
|
*/
|
|
|
|
void separator_set_line_style_from_string ( separator *sp, const char *style_str );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param sp The separator widget handle.
|
|
|
|
* @param style The new style.
|
|
|
|
*
|
|
|
|
* Sets the line style.
|
|
|
|
*/
|
|
|
|
void separator_set_line_style ( separator *sp, separator_line_style style );
|
2016-10-08 16:57:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal structure for the separator.
|
|
|
|
*/
|
|
|
|
struct _separator
|
|
|
|
{
|
2016-11-01 07:04:39 +00:00
|
|
|
widget widget;
|
|
|
|
separator_type type;
|
|
|
|
separator_line_style line_style;
|
2016-10-08 16:57:59 +00:00
|
|
|
};
|
|
|
|
|
2016-10-15 13:39:08 +00:00
|
|
|
/** Configuration value for separator style indicating no line */
|
2016-10-08 16:57:59 +00:00
|
|
|
const char *const _separator_style_none = "none";
|
2016-10-15 13:39:08 +00:00
|
|
|
/** Configuration value for separator style indicating dashed line. */
|
2016-10-08 16:57:59 +00:00
|
|
|
const char *const _separator_style_dash = "dash";
|
|
|
|
static void separator_draw ( widget *, cairo_t * );
|
|
|
|
static void separator_free ( widget * );
|
|
|
|
|
2016-12-11 11:19:46 +00:00
|
|
|
separator *separator_create ( const char *name, separator_type type, short sw )
|
2016-10-08 16:57:59 +00:00
|
|
|
{
|
|
|
|
separator *sb = g_malloc0 ( sizeof ( separator ) );
|
2016-12-27 21:19:15 +00:00
|
|
|
widget_init ( WIDGET (sb), name, SEPARATOR_CLASS_NAME );
|
2016-10-09 08:07:32 +00:00
|
|
|
sb->type = type;
|
2016-10-08 16:57:59 +00:00
|
|
|
sb->widget.x = 0;
|
|
|
|
sb->widget.y = 0;
|
2016-10-09 08:07:32 +00:00
|
|
|
if ( sb->type == S_HORIZONTAL ) {
|
|
|
|
sb->widget.w = 1;
|
2016-12-27 21:19:15 +00:00
|
|
|
sb->widget.h = MAX ( 1, sw )+sb->widget.pad.top+sb->widget.pad.bottom;
|
2016-10-09 08:07:32 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
sb->widget.h = 1;
|
2016-12-27 21:19:15 +00:00
|
|
|
sb->widget.w = MAX ( 1, sw )+sb->widget.pad.left+sb->widget.pad.right;
|
2016-10-09 08:07:32 +00:00
|
|
|
}
|
2016-10-08 16:57:59 +00:00
|
|
|
|
|
|
|
sb->widget.draw = separator_draw;
|
|
|
|
sb->widget.free = separator_free;
|
|
|
|
|
|
|
|
// Enabled by default
|
|
|
|
sb->widget.enabled = TRUE;
|
2016-12-11 11:19:46 +00:00
|
|
|
|
2016-12-27 21:19:15 +00:00
|
|
|
const char *line_style = rofi_theme_get_string ( sb->widget.class_name, sb->widget.name, NULL, "line-style", "solid");
|
2016-12-11 11:19:46 +00:00
|
|
|
separator_set_line_style_from_string ( sb, line_style );
|
2016-10-08 16:57:59 +00:00
|
|
|
return sb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void separator_free ( widget *wid )
|
|
|
|
{
|
|
|
|
separator *sb = (separator *) wid;
|
|
|
|
g_free ( sb );
|
|
|
|
}
|
|
|
|
|
2016-11-01 07:04:39 +00:00
|
|
|
void separator_set_line_style ( separator *sp, separator_line_style style )
|
|
|
|
{
|
|
|
|
if ( sp ) {
|
|
|
|
sp->line_style = style;
|
|
|
|
widget_need_redraw ( WIDGET ( sp ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void separator_set_line_style_from_string ( separator *sp, const char *style_str )
|
|
|
|
{
|
|
|
|
if ( !sp ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
separator_line_style style = S_LINE_SOLID;
|
|
|
|
if ( g_strcmp0 ( style_str, _separator_style_none ) == 0 ) {
|
|
|
|
style = S_LINE_NONE;
|
|
|
|
}
|
|
|
|
else if ( g_strcmp0 ( style_str, _separator_style_dash ) == 0 ) {
|
|
|
|
style = S_LINE_DASH;
|
|
|
|
}
|
|
|
|
separator_set_line_style ( sp, style );
|
|
|
|
}
|
|
|
|
|
2016-10-08 16:57:59 +00:00
|
|
|
static void separator_draw ( widget *wid, cairo_t *draw )
|
|
|
|
{
|
2016-10-09 08:07:32 +00:00
|
|
|
separator *sep = (separator *) wid;
|
2016-11-01 07:04:39 +00:00
|
|
|
if ( sep->line_style == S_LINE_NONE ) {
|
|
|
|
// Nothing to draw.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
color_separator ( draw );
|
2016-12-27 21:19:15 +00:00
|
|
|
rofi_theme_get_color ( wid->class_name, wid->name, NULL, "foreground", draw );
|
2016-11-01 07:04:39 +00:00
|
|
|
if ( sep->line_style == S_LINE_DASH ) {
|
|
|
|
const double dashes[1] = { 4 };
|
|
|
|
cairo_set_dash ( draw, dashes, 1, 0.0 );
|
|
|
|
}
|
|
|
|
if ( sep->type == S_HORIZONTAL ) {
|
|
|
|
cairo_set_line_width ( draw, wid->h );
|
2016-12-27 21:19:15 +00:00
|
|
|
int height= wid->h-wid->pad.top-wid->pad.bottom;
|
|
|
|
double half = height / 2.0;
|
|
|
|
cairo_move_to ( draw, wid->x+wid->pad.left, wid->y + wid->pad.top +half );
|
|
|
|
cairo_line_to ( draw, wid->x+wid->w-wid->pad.right, wid->y +wid->pad.top + half );
|
2016-11-01 07:04:39 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cairo_set_line_width ( draw, wid->w );
|
|
|
|
double half = wid->w / 2.0;
|
2016-12-27 21:19:15 +00:00
|
|
|
cairo_move_to ( draw, wid->x + wid->pad.left + half, wid->y +wid->pad.top);
|
|
|
|
cairo_line_to ( draw, wid->x + wid->pad.left + half, wid->y + wid->h-wid->pad.bottom );
|
2016-10-08 16:57:59 +00:00
|
|
|
}
|
2016-11-01 07:04:39 +00:00
|
|
|
cairo_stroke ( draw );
|
2016-10-08 16:57:59 +00:00
|
|
|
}
|