1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Add auto-detect option to DPI setting.

This commit is contained in:
Dave Davenport 2017-01-21 12:58:52 +01:00
parent b0870e02f7
commit 0ebd6a260b
13 changed files with 82 additions and 45 deletions

View file

@ -51,6 +51,7 @@
[ -no-show-match ] [ -no-show-match ]
[ -theme *filename* ] [ -theme *filename* ]
[ -theme-str *string* ] [ -theme-str *string* ]
[ -dpi *dpi* ]
## DESCRIPTION ## DESCRIPTION
@ -408,6 +409,13 @@ For example
This option can be specified multiple times. This option can be specified multiple times.
`-dpi` *number*
Override the default DPI setting.
If set to `0` it tries to auto-detect based on monitor.
### PATTERN setting ### PATTERN setting
`-terminal` `-terminal`

View file

@ -1,13 +1,13 @@
.\" generated with Ronn/v0.7.3 .\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3 .\" http://github.com/rtomayko/ronn/tree/0.7.3
. .
.TH "ROFI\-MANPAGE" "" "2017-01-18" "" "" .TH "ROFI\-MANPAGE" "" "January 2017" "" ""
. .
.SH "NAME" .SH "NAME"
\fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement \fBrofi\fR \- A window switcher, run launcher, ssh dialog and dmenu replacement
. .
.SH "SYNOPSIS" .SH "SYNOPSIS"
\fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-display \fIdisplay\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-window\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-cycle ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-matching \fImethod\fR ] [ \-tokenize ] [ \-no\-click\-to\-exit ] [ \-threads \fInum\fR ] [ \-config \fIfilename\fR ] [ \-no\-show\-match ] [ \-theme \fIfilename\fR ] [ \-theme\-str \fIstring\fR ] \fBrofi\fR [ \-width \fIpct_scr\fR ] [ \-lines \fIlines\fR ] [ \-columns \fIcolumns\fR ] [ \-font \fIpangofont\fR ] [ \-terminal \fIterminal\fR ] [ \-location \fIposition\fR ] [ \-fixed\-num\-lines ] [ \-padding \fIpadding\fR ] [ \-display \fIdisplay\fR ] [ \-bw \fIwidth\fR ] [ \-dmenu [ \-p \fIprompt\fR ] [ \-sep \fIseparator\fR ] [ \-l \fIselected line\fR ] [ \-mesg ] [ \-select ] [ \-input \fIinput\fR ] ] [ \-filter \fIfilter\fR ] [ \-ssh\-client \fIclient\fR ] [ \-ssh\-command \fIcommand\fR ] [ \-window\-command \fIcommand\fR ] [ \-disable\-history ] [ \-levenshtein\-sort ] [ \-case\-sensitive ] [ \-cycle ] [ \-show \fImode\fR ] [ \-modi \fImode1,mode2\fR ] [ \-eh \fIelement height\fR ] [ \-e \fImessage\fR] [ \-a \fIrow\fR ] [ \-u \fIrow\fR ] [ \-pid \fIpath\fR ] [ \-version ] [ \-help ] [ \-dump\-xresources ] [ \-dump\-xresources\-theme ] [ \-auto\-select ] [ \-parse\-hosts ] [ \-no\-parse\-known\-hosts ] [ \-combi\-modi \fImode1,mode2\fR ] [ \-normal\-window ] [ \-fake\-transparency ] [ \-matching \fImethod\fR ] [ \-tokenize ] [ \-no\-click\-to\-exit ] [ \-threads \fInum\fR ] [ \-config \fIfilename\fR ] [ \-no\-show\-match ] [ \-theme \fIfilename\fR ] [ \-theme\-str \fIstring\fR ] [ \-dpi \fIdpi\fR ]
. .
.SH "DESCRIPTION" .SH "DESCRIPTION"
\fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\. \fBrofi\fR is an X11 popup window switcher, run dialog, dmenu replacement and more\. It focuses on being fast to use and have minimal distraction\. It supports keyboard and mouse navigation, type to filter, tokenized search and more\.
@ -668,6 +668,12 @@ rofi \-theme\-str \'#window { fullscreen: true; }\'
.P .P
This option can be specified multiple times\. This option can be specified multiple times\.
. .
.P
\fB\-dpi\fR \fInumber\fR
.
.P
Override the default DPI setting\. If set to \fB0\fR it tries to auto\-detect based on monitor\.
.
.SS "PATTERN setting" .SS "PATTERN setting"
\fB\-terminal\fR \fB\-terminal\fR
. .

View file

@ -209,8 +209,6 @@ char * rofi_latin_to_utf8_strdup ( const char *input, gssize length );
*/ */
PangoAttrList *token_match_get_pango_attr ( ThemeHighlight th, GRegex **tokens, const char *input, PangoAttrList *retv ); PangoAttrList *token_match_get_pango_attr ( ThemeHighlight th, GRegex **tokens, const char *input, PangoAttrList *retv );
/** /**
* @param pattern The user input to match against. * @param pattern The user input to match against.
* @param plen Pattern length. * @param plen Pattern length.

View file

@ -97,6 +97,7 @@ typedef struct _workarea
int w; int w;
/** Height of the monitor */ /** Height of the monitor */
int h; int h;
int mw, mh;
/** Output name of the monitor, e.g. eDP1 or VGA-1 */ /** Output name of the monitor, e.g. eDP1 or VGA-1 */
char *name; char *name;
/** Pointer to next monitor */ /** Pointer to next monitor */

View file

@ -889,4 +889,3 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st
g_free ( dp ); g_free ( dp );
return -lefts; return -lefts;
} }

View file

@ -63,7 +63,6 @@
/** The Rofi View log domain */ /** The Rofi View log domain */
#define LOG_DOMAIN "View" #define LOG_DOMAIN "View"
#include "xcb.h" #include "xcb.h"
/** /**
* @param state The handle to the view * @param state The handle to the view
@ -562,7 +561,8 @@ static void filter_elements ( thread_state *t, G_GNUC_UNUSED gpointer user_data
glong slen = g_utf8_strlen ( str, -1 ); glong slen = g_utf8_strlen ( str, -1 );
if ( config.levenshtein_sort || config.matching_method != MM_FUZZY ) { if ( config.levenshtein_sort || config.matching_method != MM_FUZZY ) {
t->state->distance[i] = levenshtein ( pattern, plen, str, slen ); t->state->distance[i] = levenshtein ( pattern, plen, str, slen );
} else { }
else {
t->state->distance[i] = rofi_scorer_fuzzy_evaluate ( pattern, plen, str, slen ); t->state->distance[i] = rofi_scorer_fuzzy_evaluate ( pattern, plen, str, slen );
} }
g_free ( str ); g_free ( str );
@ -666,11 +666,27 @@ void __create_window ( MenuFlags menu_flags )
PangoContext *p = pango_cairo_create_context ( CacheState.edit_draw ); PangoContext *p = pango_cairo_create_context ( CacheState.edit_draw );
// Set the font options from the xlib surface // Set the font options from the xlib surface
pango_cairo_context_set_font_options ( p, fo ); pango_cairo_context_set_font_options ( p, fo );
CacheState.main_window = box;
CacheState.flags = menu_flags;
monitor_active ( &( CacheState.mon ) );
// Setup dpi // Setup dpi
if ( config.dpi > 0 ) { if ( config.dpi > 0 ) {
PangoFontMap *font_map = pango_cairo_font_map_get_default (); PangoFontMap *font_map = pango_cairo_font_map_get_default ();
pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, (double) config.dpi ); pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, (double) config.dpi );
} }
else if ( config.dpi == 0 ) {
// Auto-detect mode.
double dpi = 96;
if ( CacheState.mon.mh > 0 ) {
dpi = ( CacheState.mon.h * 25.4 ) / (double) ( CacheState.mon.mh );
}
else {
dpi = ( xcb->screen->height_in_pixels * 25.4 ) / (double) ( xcb->screen->height_in_millimeters );
}
PangoFontMap *font_map = pango_cairo_font_map_get_default ();
pango_cairo_font_map_set_resolution ( (PangoCairoFontMap *) font_map, dpi );
}
// Setup font. // Setup font.
// Dummy widget. // Dummy widget.
container *win = container_create ( "window.box" ); container *win = container_create ( "window.box" );
@ -710,10 +726,6 @@ void __create_window ( MenuFlags menu_flags )
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, 4, "rofi" ); xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, 4, "rofi" );
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4, "rofi" ); xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4, "rofi" );
CacheState.main_window = box;
CacheState.flags = menu_flags;
monitor_active ( &( CacheState.mon ) );
char *transparency = rofi_theme_get_string ( WIDGET ( win ), "transparency", NULL ); char *transparency = rofi_theme_get_string ( WIDGET ( win ), "transparency", NULL );
if ( transparency == NULL && config.fake_transparency ) { if ( transparency == NULL && config.fake_transparency ) {
transparency = config.fake_background; transparency = config.fake_background;

View file

@ -210,6 +210,9 @@ static workarea * x11_get_monitor_from_output ( xcb_randr_output_t out )
retv->w = crtc_reply->width; retv->w = crtc_reply->width;
retv->h = crtc_reply->height; retv->h = crtc_reply->height;
retv->mw = op_reply->mm_width;
retv->mh = op_reply->mm_height;
char *tname = (char *) xcb_randr_get_output_info_name ( op_reply ); char *tname = (char *) xcb_randr_get_output_info_name ( op_reply );
int tname_len = xcb_randr_get_output_info_name_length ( op_reply ); int tname_len = xcb_randr_get_output_info_name_length ( op_reply );
@ -337,6 +340,16 @@ void x11_dump_monitor_layout ( void )
printf ( "%s name%s: %s\n", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->name ); printf ( "%s name%s: %s\n", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->name );
printf ( "%s position%s: %d,%d\n", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->x, iter->y ); printf ( "%s position%s: %d,%d\n", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->x, iter->y );
printf ( "%s size%s: %d,%d\n", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->w, iter->h ); printf ( "%s size%s: %d,%d\n", ( is_term ) ? color_bold : "", is_term ? color_reset : "", iter->w, iter->h );
if ( iter->mw > 0 && iter->mh > 0 ) {
printf ( "%s size%s: %dmm,%dmm dpi: %.0f,%.0f\n",
( is_term ) ? color_bold : "",
is_term ? color_reset : "",
iter->mw,
iter->mh,
iter->w * 25.4 / (double) iter->mw,
iter->h * 25.4 / (double) iter->mh
);
}
printf ( "\n" ); printf ( "\n" );
} }
} }