Skip to content

Commit e923fbe

Browse files
committed
WIP: derive default selection width from display dpi
Closes: #285
1 parent c6f9138 commit e923fbe

File tree

6 files changed

+13
-3
lines changed

6 files changed

+13
-3
lines changed

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ AS_IF([test "x$orig_CFLAGS" = "x"], [
2828
AX_APPEND_LINK_FLAGS(["-flto"])
2929
])
3030
m4_foreach([SCROT_FLAG],
31-
[["-O3"], ["-Wall"], ["-Wextra"], ["-Wpedantic"]], [
31+
[["-O3"], ["-Wall"], ["-Wextra"], ["-Wpedantic"], ["-fno-math-errno"]], [
3232
AX_APPEND_COMPILE_FLAGS(["SCROT_FLAG"])
3333
AS_IF([test "x$LTO_ENABLED" = "xyes"], [
3434
AX_APPEND_LINK_FLAGS(["SCROT_FLAG"])

deps.pc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ Name: scrot's mandatory dependencies
22
Description: ditto
33
Version: infinite
44
Cflags: -D_XOPEN_SOURCE=700L
5+
Libs: -lm
56
Requires: x11 imlib2 >= 1.11.0 xcomposite >= 0.2.0 xext xfixes >= 5.0.1 xinerama >= 1.1.3

man/scrot.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ SELECTION STYLE
175175

176176
Without the -l option, a default style is used:
177177

178-
mode=auto,style=solid,width=1,opacity=100
178+
mode=auto,style=solid,width=1,opacity=100 # TODO: update the default width here
179179

180180
Example:
181181

src/options.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ struct ScrotOptions opt = {
6868
.quality = 75,
6969
.compression = 7,
7070
.lineStyle = LineSolid,
71-
.lineWidth = 1,
7271
.lineOpacity = SELECTION_OPACITY_DEFAULT,
7372
.stackDirection = HORIZONTAL,
7473
.outputFile = defaultOutputFile,

src/scrot_selection.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3939
#include <stdlib.h>
4040
#include <string.h>
4141
#include <time.h>
42+
#include <math.h>
4243

4344
#include <Imlib2.h>
4445
#include <X11/Xlib.h>
@@ -423,6 +424,14 @@ Imlib_Image scrotSelectionSelectMode(void)
423424
opt.lineMode = LINE_MODE_CLASSIC;
424425
}
425426

427+
if (opt.lineWidth == 0) {
428+
double mmToInches = 1 / 25.4;
429+
double inchesDiag = hypot(scr->mwidth, scr->mheight) * mmToInches;
430+
double pixelsDiag = hypot(scr->width, scr->height);
431+
double dpi = round(pixelsDiag / inchesDiag);
432+
opt.lineWidth = CLAMP(round(dpi / 75.0), 1, 8);
433+
}
434+
426435
if (opt.delaySelection)
427436
scrotDoDelay();
428437

src/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4343

4444
#define ARRAY_COUNT(X) (sizeof(X) / sizeof(0[X]))
4545
#define MAX(A, B) ((A) > (B) ? (A) : (B))
46+
#define CLAMP(X, LO, HI) ((X) < (LO) ? (LO) : ((X) > (HI) ? (HI) : (X)))
4647

4748
typedef struct {
4849
char *buf;

0 commit comments

Comments
 (0)