-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from sergei-mironov/github-ci-fancy
GitHub ci fancy
- Loading branch information
Showing
7 changed files
with
207 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
name: Build and Package | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
deb_file: ${{ steps.package.outputs.deb_file }} | ||
version: ${{ steps.package.outputs.version }} | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up CMake | ||
uses: jwlawson/[email protected] | ||
with: | ||
cmake-version: '3.23' | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y libx11-dev libxkbfile-dev dpkg-dev fakeroot | ||
- name: Verify CMake version | ||
run: cmake --version | ||
|
||
- name: Build project | ||
run: | | ||
mkdir -p build | ||
cd build | ||
cmake .. | ||
make | ||
- name: Package project | ||
id: package | ||
run: | | ||
cd build | ||
cmake --build . --target create_deb | ||
DEB_FILE=$(ls *.deb) | ||
VERSION=$(echo $DEB_FILE | grep -oP '\d+\.\d+\.\d+') | ||
echo "DEB_FILE=${DEB_FILE}" >> "$GITHUB_OUTPUT" | ||
echo "VERSION=${VERSION}" >> "$GITHUB_OUTPUT" | ||
- name: Upload .deb package as artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: xkb-switch-deb | ||
path: build/*.deb | ||
|
||
publish: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
|
||
steps: | ||
- name: Download .deb package | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: xkb-switch-deb | ||
|
||
- name: Create GitHub Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
VERSION: ${{ needs.build.outputs.version }} | ||
with: | ||
tag_name: "v${{ env.VERSION }}.${{ github.run_number }}" # Example of using a pseudo semantic versioning | ||
release_name: "Version ${{ env.VERSION }}, pipeline run ${{ github.run_number }}" | ||
draft: true # Ensure the release is published | ||
prerelease: false # Change to false if you do not want it as a prerelease | ||
|
||
- name: Upload Release Asset | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
DEB_FILE: ${{ needs.build.outputs.deb_file }} | ||
VERSION: ${{ needs.build.outputs.version }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./${{ env.DEB_FILE }} | ||
asset_name: xkb-switch-${{ env.VERSION }}.${{ github.run_number }}.deb | ||
asset_content_type: application/octet-stream | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) | ||
CMAKE_MINIMUM_REQUIRED(VERSION 3.10) | ||
|
||
PROJECT( XKB-SWITCH ) | ||
SET(MAJOR_VERSION 2) | ||
SET(MINOR_VERSION 0) | ||
SET(MINOR_VERSION 1) | ||
SET(RELEASE_VERSION 1) | ||
SET(XKBSWITCH_VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.${RELEASE_VERSION}) | ||
ADD_DEFINITIONS(-DXKBSWITCH_VERSION="${XKBSWITCH_VERSION}") | ||
|
@@ -84,3 +84,25 @@ endfunction() | |
|
||
# Compress and install man page | ||
install_man(xkb-switch 1) | ||
|
||
# Set CPack variables | ||
SET(CPACK_PACKAGE_NAME "xkb-switch") | ||
SET(CPACK_PACKAGE_VERSION ${XKBSWITCH_VERSION}) | ||
SET(CPACK_PACKAGE_CONTACT "Sergei Mironov <[email protected]>") | ||
|
||
# Set Debian-specific variables | ||
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "Sergey Korablin <[email protected]>") # required | ||
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.2.5)") # update as needed | ||
SET(CPACK_DEBIAN_PACKAGE_SECTION "utils") # update as needed | ||
SET(CPACK_DEBIAN_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR}) | ||
|
||
# Include CPack | ||
include(CPack) | ||
|
||
# Custom target to run CPack | ||
ADD_CUSTOM_TARGET(create_deb | ||
COMMAND ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR} cpack -G DEB | ||
DEPENDS xkb-switch | ||
COMMENT "Packaging the project to .deb with CPack" | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* Copyright (C) 2008 by Jay Bromley <[email protected]> | ||
* Copyright (C) 2010-2023 by Sergei Mironov | ||
* Copyright (C) 2010-2024 by Sergei Mironov | ||
* | ||
* This file is part of Xkb-switch. | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
|
@@ -112,6 +112,32 @@ struct XkbRF_VarDefsRec_wrapper { | |
} | ||
}; | ||
|
||
struct XkbKeyboardWrapper { | ||
XkbDescPtr ptr; | ||
XkbKeyboardWrapper(XkbDescPtr p) : ptr(p) {} | ||
~XkbKeyboardWrapper() { | ||
if (ptr) { | ||
|
||
XkbFreeKeyboard(ptr, 0, True); | ||
} | ||
} | ||
// Disable copying | ||
XkbKeyboardWrapper(const XkbKeyboardWrapper&) = delete; | ||
XkbKeyboardWrapper& operator=(const XkbKeyboardWrapper&) = delete; | ||
}; | ||
|
||
struct XGetAtomNameWrapper { | ||
Display* display; | ||
char* ptr; | ||
XGetAtomNameWrapper(Display* d, Atom atom) | ||
: display(d), ptr(XGetAtomName(d, atom)) {} | ||
~XGetAtomNameWrapper() { | ||
if (ptr) { | ||
XFree(ptr); | ||
} | ||
} | ||
}; | ||
|
||
layout_variant_strings XKeyboard::get_layout_variant() | ||
{ | ||
XkbRF_VarDefsRec_wrapper vdr; | ||
|
@@ -196,6 +222,50 @@ int XKeyboard::get_group() const | |
return static_cast<int>(xkbState.group); | ||
} | ||
|
||
std::string XKeyboard::get_long_group_name() const { | ||
if (_display == nullptr) { | ||
throw std::runtime_error("Display not opened."); | ||
} | ||
|
||
XkbStateRec xkbState; | ||
|
||
if (XkbGetState(_display, _deviceId, &xkbState) != Success) { | ||
throw std::runtime_error("Failed to get keyboard state."); | ||
} | ||
|
||
XkbDescPtr descPtr = XkbGetKeyboard(_display, XkbAllComponentsMask, _deviceId); | ||
if (descPtr == nullptr) { | ||
throw std::runtime_error("Failed to get keyboard description."); | ||
} | ||
|
||
XkbKeyboardWrapper desc(descPtr); | ||
|
||
if (desc.ptr->names == nullptr) { | ||
throw std::runtime_error("Failed to get keyboard names."); | ||
} | ||
|
||
Status ErrorGetControls = XkbGetControls(_display, XkbAllComponentsMask, desc.ptr); | ||
if (ErrorGetControls != Success || desc.ptr->ctrls == nullptr) { | ||
throw std::runtime_error("Failed to get keyboard controls."); | ||
} | ||
|
||
int num_groups = desc.ptr->ctrls->num_groups; | ||
if (xkbState.group >= num_groups) { | ||
throw std::runtime_error("Group index out of range."); | ||
} | ||
|
||
XGetAtomNameWrapper groupName(_display, desc.ptr->names->groups[xkbState.group]); | ||
if (groupName.ptr == nullptr) { | ||
throw std::runtime_error("Failed to get group name."); | ||
} | ||
|
||
std::string longGroupName = groupName.ptr; | ||
|
||
return longGroupName; | ||
} | ||
|
||
|
||
|
||
// returns true if symbol is ok | ||
bool filter(const string_vector& nonsyms, const std::string& symbol) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters