Added stylus-only mode for PDF drawing and annotations. (#27)

This change introduces a "Stylus Only Mode" toggle in the annotation dock, allowing users to restrict drawing input to stylus pens while maintaining touch support for scrolling and navigation.

Key changes include:
- Added `isStylusOnlyMode` state and persistence logic in `PdfViewerScreen`.
- Updated `AnnotationDock` with a toggle button for the new mode.
- Modified pointer input handling in `PdfPageComposable` and `PdfVerticalReader` to filter touch events when stylus-only mode is active.
- Adjusted tap gesture detection to ensure scrolling and page clicks still function correctly under various input modes.
This commit is contained in:
Aryan 2026-03-04 13:18:26 +05:30 committed by GitHub
parent d459535ffd
commit b47b6a9164
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 97 additions and 25 deletions

View file

@ -291,12 +291,23 @@ private const val PDF_AUTO_SCROLL_LOCKED_KEY = "pdf_auto_scroll_locked"
private const val PDF_AUTO_SCROLL_USE_SLIDER_KEY = "pdf_auto_scroll_use_slider"
private const val PDF_AUTO_SCROLL_MIN_SPEED_KEY = "pdf_auto_scroll_min_speed"
private const val PDF_AUTO_SCROLL_MAX_SPEED_KEY = "pdf_auto_scroll_max_speed"
private const val STYLUS_ONLY_MODE_KEY = "stylus_only_mode"
private fun savePdfAutoScrollMinSpeed(context: Context, speed: Float) {
val prefs = context.getSharedPreferences(SETTINGS_PREFS_NAME, Context.MODE_PRIVATE)
prefs.edit { putFloat(PDF_AUTO_SCROLL_MIN_SPEED_KEY, speed) }
}
private fun saveStylusOnlyMode(context: Context, isEnabled: Boolean) {
val prefs = context.getSharedPreferences(SETTINGS_PREFS_NAME, Context.MODE_PRIVATE)
prefs.edit { putBoolean(STYLUS_ONLY_MODE_KEY, isEnabled) }
}
private fun loadStylusOnlyMode(context: Context): Boolean {
val prefs = context.getSharedPreferences(SETTINGS_PREFS_NAME, Context.MODE_PRIVATE)
return prefs.getBoolean(STYLUS_ONLY_MODE_KEY, false)
}
private fun loadPdfAutoScrollMinSpeed(context: Context): Float {
val prefs = context.getSharedPreferences(SETTINGS_PREFS_NAME, Context.MODE_PRIVATE)
return prefs.getFloat(PDF_AUTO_SCROLL_MIN_SPEED_KEY, 0.1f)
@ -649,6 +660,7 @@ fun PdfViewerScreen(
var isAutoScrollLocked by remember { mutableStateOf(loadPdfAutoScrollLocked(context)) }
var autoScrollUseSlider by remember { mutableStateOf(loadPdfAutoScrollUseSlider(context)) }
var isStylusOnlyMode by remember { mutableStateOf(loadStylusOnlyMode(context)) }
var currentTtsMode by remember { mutableStateOf(loadTtsMode(context)) }
var showTtsSettingsSheet by remember { mutableStateOf(false) }
@ -3298,6 +3310,7 @@ fun PdfViewerScreen(
}
},
richTextController = richTextController,
isStylusOnlyMode = isStylusOnlyMode,
isEditMode = isDrawingActive,
textBoxes = textBoxes.filter { it.pageIndex == pageIndex },
selectedTextBoxId = selectedTextBoxId,
@ -3649,6 +3662,7 @@ fun PdfViewerScreen(
},
selectedTool = selectedTool,
richTextController = richTextController,
isStylusOnlyMode = isStylusOnlyMode,
isEditMode = isDrawingActive,
textBoxes = textBoxes,
selectedTextBoxId = selectedTextBoxId,
@ -4894,6 +4908,11 @@ fun PdfViewerScreen(
activePenColor = dockPenColor,
activeHighlighterColor = dockHighlighterColor,
lastPenTool = lastPenTool,
isStylusOnlyMode = isStylusOnlyMode,
onToggleStylusOnlyMode = {
isStylusOnlyMode = !isStylusOnlyMode
saveStylusOnlyMode(context, isStylusOnlyMode)
},
onToolClick = { clickedTool ->
if (clickedTool == InkType.ERASER) {
annotationSettingsRepo.updateSelectedTool(