Skip to content

Commit

Permalink
fix monitor index preference
Browse files Browse the repository at this point in the history
  • Loading branch information
youxkei committed Jun 1, 2024
1 parent 40e77fd commit a312201
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 66 deletions.
52 changes: 1 addition & 51 deletions .github/workflows/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
name: Windows

on:
pull_request:
branches:
- "*"
push:
branches:
- master
- feature/*
- hotfix/*
tags:
- v*
schedule:
- cron: "30 0 * * 1" # Every Monday at half past midnight UTC
branches: ["*"]

jobs:
build:
Expand Down Expand Up @@ -97,43 +87,3 @@ jobs:
target/${{ matrix.target }}/release/komorebic.pdb
target/${{ matrix.target }}/release/komorebic-no-console.pdb
target/wix/komorebi-*.msi
retention-days: 7
- name: Check GoReleaser
uses: goreleaser/goreleaser-action@v3
with:
version: latest
args: build --skip=validate --clean

# Release
- name: Generate changelog
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
if ! type kokai >/dev/null; then cargo install --locked kokai --force; fi
kokai release --no-emoji --add-links github:commits,issues --ref "$(git tag --points-at HEAD)" >"CHANGELOG.md"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v3
if: startsWith(github.ref, 'refs/tags/v')
with:
version: latest
args: release --skip=validate --clean --release-notes=CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SCOOP_TOKEN: ${{ secrets.SCOOP_TOKEN }}
- name: Add MSI to release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/v')
with:
files: "target/wix/komorebi-*.msi"

winget:
name: Publish to WinGet
runs-on: ubuntu-latest
needs: build
if: startsWith(github.ref, 'refs/tags/v')

steps:
- uses: vedantmgoyal2009/winget-releaser@v2
with:
identifier: LGUG2Z.komorebi
token: ${{ secrets.WINGET_TOKEN }}
3 changes: 3 additions & 0 deletions komorebi/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub struct Monitor {
last_focused_workspace: Option<usize>,
#[getset(get_mut = "pub")]
workspace_names: HashMap<usize, String>,
#[getset(get_copy = "pub", set = "pub")]
index_preference: Option<usize>,
}

impl_ring_elements!(Monitor, Workspace);
Expand All @@ -61,6 +63,7 @@ pub fn new(id: isize, size: Rect, work_area_size: Rect, name: String) -> Monitor
workspaces,
last_focused_workspace: None,
workspace_names: HashMap::default(),
index_preference: None,
}
}

Expand Down
5 changes: 5 additions & 0 deletions komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,11 @@ impl WindowsApi {
monitors as *mut Ring<Monitor> as isize,
)?;

monitors
.elements_mut()
.make_contiguous()
.sort_by(|a, b| a.index_preference().cmp(&b.index_preference()));

Ok(())
}

Expand Down
18 changes: 3 additions & 15 deletions komorebi/src/windows_callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,34 +111,22 @@ pub extern "system" fn enum_display_monitor(
}

let monitor_index_preferences = MONITOR_INDEX_PREFERENCES.lock();
let mut index_preference = None;
for (index, monitor_size) in &*monitor_index_preferences {
if m.size() == monitor_size {
index_preference = Option::from(index);
m.set_index_preference(Some(*index));
}
}

let display_index_preferences = DISPLAY_INDEX_PREFERENCES.lock();
for (index, device) in &*display_index_preferences {
if let Some(known_device) = m.device_id() {
if device == known_device {
index_preference = Option::from(index);
m.set_index_preference(Some(*index));
}
}
}

if monitors.elements().is_empty() {
monitors.elements_mut().push_back(m);
} else if let Some(preference) = index_preference {
let current_len = monitors.elements().len();
if *preference > current_len {
monitors.elements_mut().reserve(1);
}

monitors.elements_mut().insert(*preference, m);
} else {
monitors.elements_mut().push_back(m);
}
monitors.elements_mut().push_back(m);
}

true.into()
Expand Down

0 comments on commit a312201

Please sign in to comment.