Skip to content

Commit b136a9d

Browse files
authored
Expose vsync setting (#62)
* Add vsync setting * Remove vsync command
1 parent e5bbc75 commit b136a9d

4 files changed

Lines changed: 11 additions & 14 deletions

File tree

docs/settings.gen.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ For examples and default values see [here](../config/settings.json)
123123
| `ui.tab-header-width` | int | 30 | Width of tab layout headers in characters |
124124
| `ui.theme` | string | "app://themes/tokyo-night-color-theme.json" | VFS path of the theme. |
125125
| `ui.toast-duration` | int | 8000 | How long toasts are displayed for, in milliseconds. |
126+
| `ui.vsync` | bool | true | Enable vertical sync to prevent screen tearing. |
126127
| `ui.which-key-delay` | int | 250 | After how many milliseconds the which key window opens. |
127128
| `ui.which-key-height` | int | 6 | How many rows tall the window showing next possible inputs should be. |
128129
| `ui.which-key-no-progress` | bool | false | If true then the window showing next possible inputs will be displayed even when no keybinding is in progress (i.e. it will always be shown). |

scripting/editor_api_wasm.nim

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,6 @@ proc loadTheme*(name: string; force: bool = false) {.gcsafe, raises: [].} =
292292
argsJsonString.cstring)
293293

294294

295-
proc editor_vsync_void_App_bool_wasm(arg: cstring): cstring {.importc.}
296-
proc vsync*(enabled: bool) {.gcsafe, raises: [].} =
297-
var argsJson = newJArray()
298-
argsJson.add enabled.toJson()
299-
let argsJsonString = $argsJson
300-
let res {.used.} = editor_vsync_void_App_bool_wasm(argsJsonString.cstring)
301-
302-
303295
proc editor_openSession_void_App_string_bool_float_float_float_wasm(arg: cstring): cstring {.
304296
importc.}
305297
proc openSession*(root: string = "home://"; preview: bool = true;

src/app.nim

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -765,18 +765,18 @@ proc applySettingsFromAppOptions(self: App) =
765765

766766
proc applyFontSettings(self: App) =
767767
let fontRegular = self.uiSettings.fontFamily.get
768-
let fontBold = self.uiSettings.fontFamilyBold.get
768+
let fontBold = self.uiSettings.fontFamilyBold.get
769769
let fontItalic = self.uiSettings.fontFamilyItalic.get
770770
let fontBoldItalic = self.uiSettings.fontFamilyBoldItalic.get
771-
771+
772772
if fontRegular != self.fontRegular or
773773
fontBold != self.fontBold or
774774
fontItalic != self.fontItalic or
775775
fontBoldItalic != self.fontBoldItalic:
776776
log lvlInfo, &"Applying font settings: {fontRegular}, {fontBold}, {fontItalic}, {fontBoldItalic}"
777777
self.fontRegular = fontRegular
778778
self.fontBold = fontBold
779-
self.fontItalic = fontItalic
779+
self.fontItalic = fontItalic
780780
self.fontBoldItalic = fontBoldItalic
781781
self.platform.setFont(self.fontRegular, self.fontBold, self.fontItalic, self.fontBoldItalic, self.fallbackFonts)
782782

@@ -874,6 +874,8 @@ proc newApp*(backend: api.Backend, platform: Platform, services: Services, optio
874874
self.uiSettings = UiSettings.new(self.config.runtime)
875875
self.generalSettings = GeneralSettings.new(self.config.runtime)
876876

877+
self.platform.setVsync(self.uiSettings.vsync.get)
878+
877879
self.applyFontSettings()
878880

879881
self.themes.setTheme(defaultTheme())
@@ -954,6 +956,8 @@ proc newApp*(backend: api.Backend, platform: Platform, services: Services, optio
954956
self.reloadThemeFromConfig = true
955957
if key == "" or key == "ui" or key.startsWith("ui.font-family"):
956958
self.applyFontSettings()
959+
if key == "" or key == "ui" or key == "ui.vsync":
960+
self.platform.setVsync(self.uiSettings.vsync.get)
957961

958962
if not options.dontRestoreConfig:
959963
if options.sessionOverride.getSome(session):
@@ -1409,9 +1413,6 @@ proc loadWorkspaceFile*(self: App, path: string) =
14091413
proc loadTheme*(self: App, name: string, force: bool = false) {.expose("editor").} =
14101414
asyncSpawn self.setTheme(fmt"app://themes/{name}.json", force)
14111415

1412-
proc vsync*(self: App, enabled: bool) {.expose("editor").} =
1413-
self.platform.setVsync(enabled)
1414-
14151416
proc loadSessionAsync(self: App, session: string, close: bool) {.async.} =
14161417
try:
14171418
let path = self.vfs.localize(session)

src/config_provider.nim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ declareSettings UiSettings, "ui":
10601060
## How long the cursor trail is. Set to 0 to disable cursor trail.
10611061
declare cursorTrailLength, int, 2
10621062

1063+
## Enable vertical sync to prevent screen tearing.
1064+
declare vsync, bool, true
1065+
10631066
## How line numbers should be displayed.
10641067
declare lineNumbers, LineNumbers, LineNumbers.Absolute
10651068

0 commit comments

Comments
 (0)