Skip to content

feat(gesture): add KWin interaction logging support#1096

Open
Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Ivy233:feat/kwin-gesture-event-log
Open

feat(gesture): add KWin interaction logging support#1096
Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Ivy233:feat/kwin-gesture-event-log

Conversation

@Ivy233
Copy link
Copy Markdown
Contributor

@Ivy233 Ivy233 commented Apr 27, 2026

Add shared logging helpers for KWin-related gesture actions and include package/version context where available. Update finalized event identifiers for existing display and input device logs.

feat(gesture): 增加 KWin 交互日志支持

为 KWin 相关手势动作增加共享日志辅助逻辑,并在可用时补充包与版本上下文。
更新显示与输入设备日志的正式事件标识。

PMS: TASK-388657

Summary by Sourcery

Add event logging for KWin-related gesture interactions and refresh event identifiers for existing display and input device telemetry.

New Features:

  • Log KWin multitask view invocations with launch source and KWin version context.
  • Log KWin split-screen activations with active application identity, version, and KWin version metadata.

Enhancements:

  • Emit multitask view and split-screen logs when triggered via touchpad or touchscreen gestures, including shared helpers to resolve app and package information from X11 and desktop metadata.

Chores:

  • Update display and input device event IDs to new finalized tracking identifiers.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Ivy233

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 27, 2026

Reviewer's Guide

Adds KWin-specific gesture interaction logging with shared helpers, including KWin and application package/version context, and updates existing display/input event IDs accordingly.

Sequence diagram for KWin multitask view gesture logging

sequenceDiagram
    actor User
    participant Manager
    participant WindowManager
    participant GestureEventLogHelpers
    participant EventLogPackage
    participant DpkgQuery

    User->>Manager: doHandle4Or5FingersSwipeUp
    Manager->>WindowManager: GetMultiTaskingStatus(display 0)
    WindowManager-->>Manager: isShowMultiTask false, isShowDesktop false
    Manager->>Manager: toggleShowMultiTasking
    Manager-->>User: multitask view shown
    Manager->>GestureEventLogHelpers: logMultiTaskViewEvent(eventLaunchTypeTouchPad)

    GestureEventLogHelpers->>DpkgQuery: packageVersion(kwin-x11)
    DpkgQuery-->>GestureEventLogHelpers: kwinVersion

    GestureEventLogHelpers->>EventLogPackage: WriteEventLog(EventLogData Tid=eventTidKWinMultiTaskView)
    EventLogPackage-->>GestureEventLogHelpers: true

    User->>Manager: handleTouchEdgeMoveStopLeave
    Manager->>Manager: showMultiTaskingWithLaunchType(eventLaunchTypeTouchScreen)
    Manager->>WindowManager: GetMultiTaskingStatus(display 0)
    WindowManager-->>Manager: isShowMultiTask false
    Manager->>Manager: toggleShowMultiTasking
    Manager->>GestureEventLogHelpers: logMultiTaskViewEvent(eventLaunchTypeTouchScreen)
Loading

Sequence diagram for KWin split screen gesture logging

sequenceDiagram
    actor User
    participant Manager
    participant WindowManager
    participant GestureEventLogHelpers
    participant X11Client
    participant EventLogPackage
    participant FileSystem
    participant DpkgQuery

    User->>Manager: doTileActiveWindowLeft
    Manager->>WindowManager: TileActiveWindow(display 0, wmTileDirectionLeft)
    WindowManager-->>Manager: success
    Manager->>GestureEventLogHelpers: logSplitScreenEvent

    GestureEventLogHelpers->>X11Client: GetActiveWindow
    X11Client-->>GestureEventLogHelpers: win

    GestureEventLogHelpers->>X11Client: GetWMClass(win)
    X11Client-->>GestureEventLogHelpers: WMClass
    GestureEventLogHelpers->>FileSystem: ReadFile(desktopPath)
    FileSystem-->>GestureEventLogHelpers: desktopEntry

    GestureEventLogHelpers->>DpkgQuery: QueryVersion(packageName)
    DpkgQuery-->>GestureEventLogHelpers: appVersion

    GestureEventLogHelpers->>DpkgQuery: packageVersion(kwin-x11)
    DpkgQuery-->>GestureEventLogHelpers: kwinVersion

    GestureEventLogHelpers->>EventLogPackage: WriteEventLog(EventLogData Tid=eventTidKWinSplitScreen)
    EventLogPackage-->>GestureEventLogHelpers: true
Loading

Class diagram for updated gesture manager and KWin event logging helpers

classDiagram
    class Manager {
        +doHandle4Or5FingersSwipeUp() error
        +doTileActiveWindowLeft() error
        +doTileActiveWindowRight() error
        +showMultiTaskingWithLaunchType(launchType string) error
        +doShowMultiTasking() error
    }

    class GestureEventLogHelpers {
        <<utility>>
        +logMultiTaskViewEvent(launchType string)
        +logSplitScreenEvent()
        +getKWinVersion() string
        +getActiveWindowAppInfo() (string, string)
        +getWindowAppNameAndVersion(win Window) (string, string)
        +getDesktopAppInfo(id string) (string, string)
        +readDesktopAppInfo(desktopPath string) (string, string)
        +getProcessAppInfo(pid uint32) (string, string)
        +packageNameByFile(path string) string
        +packageVersion(packageName string) string

        -kwinVersion string
        -kwinVersionOnce Once
    }

    class EventLogData {
        +Tid int64
        +Target string
        +Message map~string string~
    }

    class EventLogPackage {
        +WriteEventLog(data *EventLogData) bool
    }

    class X11Client {
        +GetActiveWindow() Window
        +GetWMPid(win Window) uint32
        +GetWMClass(win Window) WMClass
        +GetWMName(win Window) string
    }

    class FileSystem {
        +ReadFile(path string) []byte
        +Getenv(key string) string
    }

    class DpkgQuery {
        +QueryOwner(path string) string
        +QueryVersion(packageName string) string
    }

    Manager ..> GestureEventLogHelpers : uses
    GestureEventLogHelpers ..> EventLogPackage : writes events
    GestureEventLogHelpers ..> X11Client : queries active window
    GestureEventLogHelpers ..> FileSystem : reads desktop files
    GestureEventLogHelpers ..> DpkgQuery : resolves package info
    EventLogPackage ..> EventLogData : writes
Loading

File-Level Changes

Change Details Files
Add KWin gesture logging helpers and wire them into multitask view and split-screen gestures.
  • Introduce gesture1/event_log.go with helpers to log KWin multitask view and split screen events via session eventlog, including launch type, active app info, and KWin version.
  • Cache KWin version using dpkg-query and enrich logs with package-derived app name/version by inspecting X11 window properties, .desktop entries, or process info.
  • Update gesture actions to call logging helpers when multitask view is shown and when tiling windows left/right, ensuring errors from window manager calls are propagated before logging.
gesture1/event_log.go
gesture1/gesture_action.go
Refactor multitask show handler to support different launch types and use it for both touchpad and touchscreen gestures.
  • Extract showMultiTaskingWithLaunchType to centralize show-multitasking logic with a launch type parameter and log the corresponding multitask view event.
  • Update doShowMultiTasking and touch edge move handler to use the new helper with touchpad and touchscreen launch type constants respectively.
gesture1/gesture_action.go
gesture1/manager.go
Update finalized event IDs for display and input device logs.
  • Change display screen event TID constant to the new finalized ID.
  • Change natural scroll combined event TID constant to the new finalized ID.
display1/event_log.go
inputdevices1/event_log.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The packageVersion and packageNameByFile helpers invoke dpkg-query synchronously on each call, which may be expensive along the gesture path; consider caching per-package results (similar to kwinVersion) or performing these lookups lazily/off the critical path to avoid blocking UI interactions.
  • logSplitScreenEvent currently hardcodes launch_type to the touchpad value; if split-screen can be triggered by multiple gesture sources in future, you might want to pass the launch type as a parameter (similar to logMultiTaskViewEvent) to keep the logging format consistent.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `packageVersion` and `packageNameByFile` helpers invoke `dpkg-query` synchronously on each call, which may be expensive along the gesture path; consider caching per-package results (similar to `kwinVersion`) or performing these lookups lazily/off the critical path to avoid blocking UI interactions.
- `logSplitScreenEvent` currently hardcodes `launch_type` to the touchpad value; if split-screen can be triggered by multiple gesture sources in future, you might want to pass the launch type as a parameter (similar to `logMultiTaskViewEvent`) to keep the logging format consistent.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Ivy233 Ivy233 force-pushed the feat/kwin-gesture-event-log branch from b93d9d1 to f08a2ff Compare April 27, 2026 07:03
@Ivy233 Ivy233 force-pushed the feat/kwin-gesture-event-log branch 2 times, most recently from 2dcf603 to e56eff9 Compare April 28, 2026 07:52
Add shared logging helpers for KWin-related gesture actions and include package/version context where available. Update finalized event identifiers for existing display and input device logs.

feat(gesture): 增加 KWin 交互日志支持

为 KWin 相关手势动作增加共享日志辅助逻辑,并在可用时补充包与版本上下文。
更新显示与输入设备日志的正式事件标识。

PMS: TASK-388657
@Ivy233 Ivy233 force-pushed the feat/kwin-gesture-event-log branch from e56eff9 to be5bc89 Compare April 28, 2026 13:03
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

你好!我是 CodeGeeX。我已经仔细审查了你提供的 Git Diff 代码。这段代码主要涉及为手势功能添加事件日志记录(Event Log),并更新了部分常量定义。

以下是从语法逻辑、代码质量、代码性能和代码安全四个维度提出的详细改进意见:

1. 语法逻辑

  • 总体评价:代码逻辑清晰,符合 Go 语言规范。新增的 event_log.go 文件结构合理,packageVersion 函数的输入校验逻辑正确。
  • 版权年份更新:在 gesture1/gesture_action.gogesture1/manager.go 中,版权年份从 2018 - 2022 更新为 2018 - 2026,这是符合逻辑的,表示对代码的持续维护。
  • 错误处理改进:在 gesture_action.go 中,doTileActiveWindowLeftdoTileActiveWindowRight 等函数从直接 return 改为先检查 err 再记录日志,逻辑更加严谨,确保了只有操作成功后才记录事件日志。

2. 代码质量

  • 代码复用
    • gesture_action.go 中,提取了 showMultiTaskingWithLaunchType 函数,将原本 doShowMultiTasking 的逻辑与触发类型参数解耦。这是一个很好的重构,避免了代码重复,使得触控板和触摸屏触发多任务视图可以复用同一套逻辑。
  • 常量定义
    • gesture1/event_log.go 中定义了 eventLaunchTypeTouchPadeventLaunchTypeTouchScreen 为字符串常量。建议考虑使用 iota 定义枚举类型或整数常量,以减少内存占用并在编译期进行类型检查。不过,考虑到这些值可能是为了直接写入日志系统的 Message 字段(map[string]string),使用字符串也是合理的,但应确保与后端日志解析系统约定一致。
  • 日志一致性
    • logMultiTaskViewEvent 中打印了 launchType,而 logSplitScreenEvent 中只打印了固定文本。为了便于调试和追踪,建议在 logSplitScreenEvent 的 Debug 日志中也加上 launchTypekwin_version 信息。

3. 代码性能

  • 同步机制优化
    • getKWinVersion 使用了 sync.Once 来确保 dpkg-query 命令只执行一次。这是一个非常好的性能优化点,避免了在频繁触发手势时重复执行系统命令,减少了不必要的系统开销。
  • 外部命令调用
    • packageVersion 函数调用了 exec.Command。虽然由于 sync.Once 的存在,实际调用次数被限制为 1 次,但在高频调用的场景下(如果没有 sync.Once),这会是一个性能瓶颈。当前实现已经很好地处理了这个问题。

4. 代码安全

  • 命令注入防护
    • packageVersion 函数中,有一行检查:if packageName == "" || strings.ContainsAny(packageName, "/ \t\n\r")
    • 意见:这个检查是很好的安全实践,防止了通过 packageName 注入恶意命令(例如分号或管道符)。然而,dpkg-query 的参数 -W 接收包名,虽然做了过滤,但更安全的做法是严格限制包名字符集(例如只允许字母、数字、-+ 等 Debian 包名合法字符),而不是仅仅排除特定字符。
  • 并发安全
    • 使用了 sync.Once,保证了 kwinVersion 变量在并发环境下的初始化安全性,这是正确的做法。

总结与建议修改示例

代码整体质量很高,特别是性能优化和逻辑解耦做得很好。主要建议集中在日志调试信息的完善和常量类型的考虑上。

建议修改代码 (gesture1/event_log.go):

// 建议补充日志信息以便调试
func logSplitScreenEvent() {
    // ... data 结构定义不变 ...
    
    // 建议在日志中增加版本信息,方便排查问题
    if eventlog.WriteEventLog(data) {
        logger.Debug("EventLog: kwin split screen, version:", getKWinVersion())
    }
}

// 建议增强 packageVersion 的校验逻辑(可选)
func packageVersion(packageName string) string {
    packageName = strings.TrimSpace(packageName)
    // 仅允许字母、数字、点、减号和加号(符合 Debian 包名规范)
    // 这比排除特定字符更安全
    if packageName == "" {
        return ""
    }
    // 简单的正则校验,确保只包含合法字符
    // 注意:实际包名规则更复杂,这里仅作示例
    /* 
       如果不想引入 regexp 包,保持原有的 ContainsAny 也是可以接受的,
       但建议注释说明原因。
    */
    
    out, err := exec.Command("dpkg-query", "-W", "-f=${Version}", packageName).Output()
    if err != nil {
        return ""
    }
    return strings.TrimSpace(string(out))
}

建议修改代码 (gesture1/gesture_action.go):

// ...
func (m *Manager) doTileActiveWindowLeft() error {
    if err := m.wm.TileActiveWindow(0, wmTileDirectionLeft); err != nil {
        return err
    }
    logSplitScreenEvent()
    return nil
}
// ...

这部分代码目前的实现已经很好,无需大改,只需注意上述细节即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants