Skip to content

Commit 466ac9e

Browse files
committed
feat: allow rotating edges with display rotation
1 parent 7a0b1d3 commit 466ac9e

5 files changed

Lines changed: 37 additions & 7 deletions

File tree

app/src/main/kotlin/components/page/home/HomePage.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ fun MainPageContent(modifier: Modifier = Modifier) {
108108
supporting = stringResource(R.string.app_brightness_reset_supporting),
109109
modifier = modifier,
110110
)
111+
SwitchPreferenceListItem(
112+
value = local.repo.rotateEdges,
113+
onChange = { local.repo.rotateEdges = it },
114+
headline = stringResource(R.string.app_rotate_edges_headline),
115+
supporting = stringResource(R.string.app_rotate_edges_supporting),
116+
modifier = modifier,
117+
)
111118

112119
ListDivider()
113120
ListSectionTitle(title = stringResource(R.string.misc))

app/src/main/kotlin/impl/EdgeViewFacade.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,32 @@ class EdgeViewFacade(
7979
return
8080
}
8181

82-
val sideRotated = data.pos.id.side.rotate(displayRotation)
83-
val cornerRotated = data.pos.id.corner.rotate(displayRotation)
82+
var targetSide = data.pos.id.side
83+
var targetCorner = data.pos.id.corner
84+
85+
// edges are rotated with display rotation by default, this rotates them back.
86+
if (!local.repo.rotateEdges) {
87+
targetSide = targetSide.rotate(displayRotation)
88+
targetCorner = targetCorner.rotate(displayRotation)
89+
}
8490

8591
val lengthPct = 1f / data.side.nSegments
86-
val windowLength = when (sideRotated) {
92+
val windowLength = when (targetSide) {
8793
EdgeSide.Left, EdgeSide.Right -> displayHeight
8894
EdgeSide.Top, EdgeSide.Bottom -> displayWidth
8995
}
9096

9197
val length = (lengthPct * windowLength).roundToInt()
9298

93-
windowParams.height = when (sideRotated) {
99+
windowParams.height = when (targetSide) {
94100
EdgeSide.Left, EdgeSide.Right -> length
95101
EdgeSide.Top, EdgeSide.Bottom -> data.pos.thickness
96102
}
97-
windowParams.width = when (sideRotated) {
103+
windowParams.width = when (targetSide) {
98104
EdgeSide.Left, EdgeSide.Right -> data.pos.thickness
99105
EdgeSide.Top, EdgeSide.Bottom -> length
100106
}
101-
windowParams.gravity = when (cornerRotated) {
107+
windowParams.gravity = when (targetCorner) {
102108
EdgeCorner.BottomRight -> Gravity.BOTTOM or Gravity.RIGHT
103109
EdgeCorner.Bottom -> Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL
104110
EdgeCorner.BottomLeft -> Gravity.BOTTOM or Gravity.LEFT
@@ -118,7 +124,7 @@ class EdgeViewFacade(
118124
ctx = ctx,
119125
local = local,
120126
edgePosData = data.pos,
121-
edgeSide = sideRotated,
127+
edgeSide = targetSide,
122128
dpi = displayDensityDpi,
123129
onSeekImpl = ControlFeatureImpl.from(data.pos.onSeek),
124130
onLongClick = ActionFeatureImpl.from(data.pos.onLongClick),

app/src/main/kotlin/support/Repo.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Repo {
2525
private const val PK_FLAG_ACTIVATED = "f.activated"
2626
private const val PK_FLAG_AUTO_BOOT = "f.auto_boot"
2727
private const val PK_FLAG_BRIGHTNESS_RESET = "f.brightness_reset"
28+
private const val PK_FLAG_ROTATE_EDGES = "f.rotate_edges"
2829

2930
private const val PK_UI_LANG = "ui.lang"
3031
private const val PK_UI_COLORS = "ui.colors"
@@ -74,6 +75,12 @@ class Repo {
7475
set = { data[PK_FLAG_BRIGHTNESS_RESET] = it },
7576
)
7677

78+
/** True, to rotate edges with the rotation of the display. */
79+
var rotateEdges by property(
80+
get = { data[PK_FLAG_ROTATE_EDGES]?.asBooleanOrNull ?: false },
81+
set = { data[PK_FLAG_ROTATE_EDGES] = it },
82+
)
83+
7784
/**
7885
* Fixed-size list of edge-position configs.
7986
*

app/src/main/res/values-ar/strings-stmt.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
تفعيل السطوع التلقائي عند قفل الجهاز
9696
</string>
9797

98+
<string name="app_rotate_edges_headline">دوران الحواف</string>
99+
<string name="app_rotate_edges_supporting">
100+
إسمح للحواف بالدوران مع دوران الشاشة
101+
</string>
102+
98103
<!-- Edge -->
99104
<string name="edge_activation_headline">التفعيل</string>
100105
<string name="edge_activation_supporting">

app/src/main/res/values/strings-stmt.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@
9696
Turn on auto brightness each time the device turn on to sleep
9797
</string>
9898

99+
<string name="app_rotate_edges_headline">Rotate Edges</string>
100+
<string name="app_rotate_edges_supporting">
101+
Rotate edges with the rotation of the display
102+
</string>
103+
99104
<!-- Edge -->
100105
<string name="edge_activation_headline">Activation</string>
101106
<string name="edge_activation_supporting">

0 commit comments

Comments
 (0)