From 56008f30418e3676fa7f2d10a8e25392107a15ab Mon Sep 17 00:00:00 2001 From: abakkk Date: Wed, 9 Sep 2020 12:12:29 +0200 Subject: [PATCH] add ranges to drawing settings schema * It is no longer required to clamp the setting value in area.js. * Add a "range" property, completed with another 'step' property, to PixelSpinButton in order to directly initiate the lower and upper values of the adjustment from the relevant setting range. * Not related: fix an inversion between Pango and Cairo in element.js. --- area.js | 10 ++-- elements.js | 10 ++-- prefs.js | 46 +++++++++++++----- schemas/gschemas.compiled | Bin 6977 -> 7137 bytes ...extensions.draw-on-your-screen.gschema.xml | 6 +++ 5 files changed, 50 insertions(+), 22 deletions(-) diff --git a/area.js b/area.js index 1580a2d..321fb84 100644 --- a/area.js +++ b/area.js @@ -241,7 +241,7 @@ var DrawingArea = new Lang.Class({ while (this.squareAreaSize * 2 < Math.min(this.monitor.width, this.monitor.height)) this.squareAreaSize *= 2; } else { - this.squareAreaSize = Math.max(64, Me.drawingSettings.get_uint('square-area-size')); + this.squareAreaSize = Me.drawingSettings.get_uint('square-area-size'); } this.areaBackgroundColor = getClutterColorFromString(Me.drawingSettings.get_string('background-color'), 'BLACK'); @@ -251,16 +251,16 @@ var DrawingArea = new Lang.Class({ this.gridLineSpacing = Math.round(this.monitor.width / (5 * GRID_TILES_HORIZONTAL_NUMBER)); this.gridLineWidth = this.gridLineSpacing / 20; } else { - this.gridLineSpacing = Math.max(1, Me.drawingSettings.get_uint('grid-line-spacing')); - this.gridLineWidth = Math.round(Math.max(0.1, Me.drawingSettings.get_double('grid-line-width')) * 100) / 100; + this.gridLineSpacing = Me.drawingSettings.get_uint('grid-line-spacing'); + this.gridLineWidth = Math.round(Me.drawingSettings.get_double('grid-line-width') * 100) / 100; } this.dashOffset = Math.round(Me.drawingSettings.get_double('dash-offset') * 100) / 100; if (Me.drawingSettings.get_boolean('dash-array-auto')) { this.dashArray = [0, 0]; } else { - let on = Math.round(Math.max(0, Me.drawingSettings.get_double('dash-array-on')) * 100) / 100; - let off = Math.round(Math.max(0, Me.drawingSettings.get_double('dash-array-off')) * 100) / 100; + let on = Math.round(Me.drawingSettings.get_double('dash-array-on') * 100) / 100; + let off = Math.round(Me.drawingSettings.get_double('dash-array-off') * 100) / 100; this.dashArray = [on, off]; } }, diff --git a/elements.js b/elements.js index e7b5905..3191dfb 100644 --- a/elements.js +++ b/elements.js @@ -35,18 +35,18 @@ var getPangoFontFamilies = function() { }; const getFillRuleSvgName = function(fillRule) { - return fillRule == Pango.FillRule.EVEN_ODD ? 'evenodd' : 'nonzero'; + return fillRule == Cairo.FillRule.EVEN_ODD ? 'evenodd' : 'nonzero'; }; const getLineCapSvgName = function(lineCap) { - return lineCap == Pango.LineCap.BUTT ? 'butt' : - lineCap == Pango.LineCap.SQUASH ? 'square' : + return lineCap == Cairo.LineCap.BUTT ? 'butt' : + lineCap == Cairo.LineCap.SQUASH ? 'square' : 'round'; }; const getLineJoinSvgName = function(lineJoin) { - return lineJoin == Pango.LineJoin.MITER ? 'miter' : - lineJoin == Pango.LineJoin.BEVEL ? 'bevel' : + return lineJoin == Cairo.LineJoin.MITER ? 'miter' : + lineJoin == Cairo.LineJoin.BEVEL ? 'bevel' : 'round'; }; diff --git a/prefs.js b/prefs.js index 998cc56..dea0c8f 100644 --- a/prefs.js +++ b/prefs.js @@ -181,8 +181,8 @@ const DrawingPage = new GObject.Class({ let squareAreaAutoButton = new Gtk.CheckButton({ label: _("Auto"), name: this.schema.get_key('square-area-auto').get_summary(), tooltip_text: this.schema.get_key('square-area-auto').get_description() }); - let squareAreaSizeButton = new PixelSpinButton({ width_chars: 5, digits: 0, - adjustment: Gtk.Adjustment.new(0, 64, 32768, 1, 10, 0), + let squareAreaSizeButton = new PixelSpinButton({ width_chars: 5, digits: 0, step: 1, + range: this.schema.get_key('square-area-size').get_range(), name: this.schema.get_key('square-area-size').get_summary(), tooltip_text: this.schema.get_key('square-area-size').get_description() }); this.settings.bind('square-area-auto', squareAreaAutoButton, 'active', 0); @@ -204,12 +204,12 @@ const DrawingPage = new GObject.Class({ let gridLineAutoButton = new Gtk.CheckButton({ label: _("Auto"), name: this.schema.get_key('grid-line-auto').get_summary(), tooltip_text: this.schema.get_key('grid-line-auto').get_description() }); - let gridLineWidthButton = new PixelSpinButton({ width_chars: 5, digits: 1, - adjustment: Gtk.Adjustment.new(0, 0.1, 10, 0.1, 1, 0), + let gridLineWidthButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 0.1, + range: this.schema.get_key('grid-line-width').get_range(), name: this.schema.get_key('grid-line-width').get_summary(), tooltip_text: this.schema.get_key('grid-line-width').get_description() }); - let gridLineSpacingButton = new PixelSpinButton({ width_chars: 5, digits: 1, - adjustment: Gtk.Adjustment.new(0, 1, 16384, 1, 10, 0), + let gridLineSpacingButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 1, + range: this.schema.get_key('grid-line-spacing').get_range(), name: this.schema.get_key('grid-line-spacing').get_summary(), tooltip_text: this.schema.get_key('grid-line-spacing').get_description() }); this.settings.bind('grid-line-auto', gridLineAutoButton, 'active', 0); @@ -241,12 +241,12 @@ const DrawingPage = new GObject.Class({ let dashArrayAutoButton = new Gtk.CheckButton({ label: _("Auto"), name: this.schema.get_key('dash-array-auto').get_summary(), tooltip_text: this.schema.get_key('dash-array-auto').get_description() }); - let dashArrayOnButton = new PixelSpinButton({ width_chars: 5, digits: 1, - adjustment: Gtk.Adjustment.new(0, 0, 16384, 0.1, 1, 0), + let dashArrayOnButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 0.1, + range: this.schema.get_key('dash-array-on').get_range(), name: this.schema.get_key('dash-array-on').get_summary(), tooltip_text: this.schema.get_key('dash-array-on').get_description() }); - let dashArrayOffButton = new PixelSpinButton({ width_chars: 5, digits: 1, - adjustment: Gtk.Adjustment.new(0, 0, 16384, 0.1, 1, 0), + let dashArrayOffButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 0.1, + range: this.schema.get_key('dash-array-off').get_range(), name: this.schema.get_key('dash-array-off').get_summary(), tooltip_text: this.schema.get_key('dash-array-off').get_description() }); this.settings.bind('dash-array-auto', dashArrayAutoButton, 'active', 0); @@ -260,8 +260,8 @@ const DrawingPage = new GObject.Class({ toolsListBox.add(dashArrayRow); let dashOffsetRow = new PrefRow({ label: this.schema.get_key('dash-offset').get_summary() }); - let dashOffsetButton = new PixelSpinButton({ width_chars: 5, digits: 1, - adjustment: Gtk.Adjustment.new(0, -16384, 16384, 0.1, 1, 0), + let dashOffsetButton = new PixelSpinButton({ width_chars: 5, digits: 1, step: 0.1, + range: this.schema.get_key('dash-offset').get_range(), name: this.schema.get_key('dash-offset').get_summary(), tooltip_text: this.schema.get_key('dash-offset').get_description() }); this.settings.bind('dash-offset', dashOffsetButton, 'value', 0); @@ -523,6 +523,28 @@ const PixelSpinButton = new GObject.Class({ Name: 'DrawOnYourScreenPixelSpinButton', GTypeName: 'DrawOnYourScreenPixelSpinButton', Extends: Gtk.SpinButton, + Properties: { + 'range': GObject.param_spec_variant('range', 'range', 'GSettings range', + GLib.VariantType.new('(sv)'), null, GObject.ParamFlags.WRITABLE), + + 'step': GObject.ParamSpec.double('step', 'step', 'step increment', + GObject.ParamFlags.WRITABLE, + 0, 1000, 1) + }, + + set range(range) { + let [type, variant] = range.deep_unpack(); + if (type == 'range') { + let [min, max] = variant.deep_unpack(); + this.adjustment.set_lower(min); + this.adjustment.set_upper(max); + } + }, + + set step(step) { + this.adjustment.set_step_increment(step); + this.adjustment.set_page_increment(step * 10); + }, // Add 'px' unit. vfunc_output: function() { diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled index 85cce3ac7029a5c12ac2a8d6566f5660d0c427ac..411939e81af313d67a206371573b8906ca47bd6a 100644 GIT binary patch delta 1897 zcmZ{kZ)j6z7{#AT12w5_YN{qRjJ6a>J5nCXz$wzue zfjV85JK_}lCNz3xi>(^Nnagp)S-54rNQdplm*mXk4!8^2cWgOL&dmQvE4&wK%5!G& z2s{Qg=Q%UDDw7ClsPz6|4GS@^$AAp{A@pi~05b~}ned#T*Ycd1d^fxU+Mnml5(6-M@zGHu8)_20& zprID)Z{*D7qT*R0T!Er@lFMvhwqigEz6$BEbAG^>MGlIXMSg}R4qf<&{h15VKMl`7 z*?4f3oS7&30PeIr{SY$qL+FN|Q1KIPI6T1tCy=?b7(4-Owv1{MFmr-y@E;-Lfua@m zXXefp;rF1^t4mkOnRya8Z!tq}-IxuMGi$Fe+yxmImB%U@cw@qV4tN*z<}UlUzwkjKQlLwg5QL`nr@pUXJ-8@T(?=|*WcSeBu7@YBQgWl zLczAT8`;3j*U=5{f^;uk){`@D1dqT^L1sro6FDHM9$0wrQu6ZUw>?k=zd)P+dh%ZN7kkJv`1h#vn~9imv6noHFQE@ttJfdE z!#X%mfV?;ZVl!|ta{c%ZT)dZarNjmM)$BfVW+ z)OCIj)@jIp+j{OaIUe|byHoQk&wY1ObF{X!derh(1ytk6;elwJIpdvCXX5m@*UGa) z{`H#=IZQ;xBDHkgr!INlr;?}%!u~t8Y&!dK1E>@n!O%a=s z%f;lj@c|YpynU=fg~UY+Xu_XCkL3o4Rj3<(3q798#mdL~hTcextHDoDN`r+zjhb?W#46N|52L-gT&#QqPobMVTdt{&SQBLMA5n9z zzgYbjad&`~oZG)x&iu}W&S4oLTV?u>U2Rk$vGNu?ivDiCWGNTxJon+p(I?-Y3@R6E zYsT=eQRsFku3UT%`8>XWUb6N)qFmgjH)$Ej+hokn+OvFMCompute the lengths from the line width + 5 Dash array on The dash length in pixels + 15 Dash array off The gap between the dashes in pixels + 0 Dash offset The dash offset in pixels @@ -73,11 +76,13 @@ Compute the lengths from the screen size + 10 Grid overlay line spacing The gap between lines in pixels + 0.5 Grid overlay line width The line width in pixels @@ -102,6 +107,7 @@ Compute the size of the square area from the screen size + 512 Square area size The size of the square area in pixels