fix: 移除监听程序源代码 添加Linux用户通知

This commit is contained in:
ZiuChen 2022-09-20 13:44:07 +08:00
parent e57c0aff71
commit 9c29b5d2b7
5 changed files with 2 additions and 108 deletions

View File

@ -1,38 +0,0 @@
// https://stackoverflow.com/a/44992967
// gcc -o xclipwatch xclipwatch.c -lX11 -lXfixes
#include <X11/extensions/Xfixes.h>
#include<stdio.h>
#include <assert.h>
void WatchSelection(Display *display, Window window, const char *bufname)
{
int event_base, error_base;
XEvent event;
Atom bufid = XInternAtom(display, bufname, False);
assert( XFixesQueryExtension(display, &event_base, &error_base) );
XFixesSelectSelectionInput(display, DefaultRootWindow(display), bufid, XFixesSetSelectionOwnerNotifyMask);
while (True)
{
XNextEvent(display, &event);
if (event.type == event_base + XFixesSelectionNotify &&
((XFixesSelectionNotifyEvent*)&event)->selection == bufid)
{
printf("CLIPBOARD_CHANGE\n");
fflush(stdout);
}
}
}
int main(){
Display *display = XOpenDisplay(NULL);
Window window = DefaultRootWindow(display);
// WatchSelection(display,window,"PRIMARY");
WatchSelection(display,window,"CLIPBOARD");
XDestroyWindow(display, window);
XCloseDisplay(display);
return 0;
}

View File

@ -1,24 +0,0 @@
//
// main.swift
// clipboard-event
//
// Created by Joonhee Lee on 2021/01/30.
//
import Foundation
import Cocoa
let pasteboard: NSPasteboard = NSPasteboard.general
var count: Int = pasteboard.changeCount
var saved: String = pasteboard.string(forType: .string) ?? "null"
repeat{
usleep(500000)
if(count < pasteboard.changeCount && saved != pasteboard.string(forType: .string)){
usleep(100000)
count = pasteboard.changeCount
saved = pasteboard.string(forType: .string) ?? "null"
print("CLIPBOARD_CHANGE")
fflush(stdout)
}
}while true

View File

@ -1,44 +0,0 @@
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace clipboard_event_handler_win32 {
internal static class NativeMethods {
//Reference https://docs.microsoft.com/en-us/windows/desktop/dataxchg/wm-clipboardupdate
public const int WM_CLIPBOARDUPDATE = 0x031D;
//Reference https://www.pinvoke.net/default.aspx/Constants.HWND
public static IntPtr HWND_MESSAGE = new IntPtr(-3);
//Reference https://www.pinvoke.net/default.aspx/user32/AddClipboardFormatListener.html
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool AddClipboardFormatListener(IntPtr hwnd);
//Reference https://www.pinvoke.net/default.aspx/user32.setparent
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
}
public sealed class ClipboardNotification {
private class NotificationForm : Form {
public NotificationForm() {
//Turn the child window into a message-only window (refer to Microsoft docs)
NativeMethods.SetParent(Handle, NativeMethods.HWND_MESSAGE);
//Place window in the system-maintained clipboard format listener list
NativeMethods.AddClipboardFormatListener(Handle);
}
protected override void WndProc(ref Message m) {
//Listen for operating system messages
if (m.Msg == NativeMethods.WM_CLIPBOARDUPDATE)
{
Console.WriteLine("CLIPBOARD_CHANGE");
}
//Called for any unhandled messages
base.WndProc(ref m);
}
}
private static void Main(string[] args) {
Application.Run(new NotificationForm());
}
}
}

View File

@ -1,5 +1,5 @@
{
"title": "重要版本更新提示",
"content": "1. 如果你是第一次使用此插件, 请务必设置跟随主程序启动选项, 否则可能导致剪贴板记录丢失</br>2. 插件内的收藏栏将在最近一个版本中移除, 届时点击收藏按钮将跳转到备忘快贴, 请尽快将已有数据保存, 使用备忘快贴代替</br>3. 插件使用过程中遇到任何问题, 请到论坛发布页回帖或加入QQ群反馈",
"version": 1
"content": "1. 如果你是第一次使用此插件, 请务必设置跟随主程序启动选项, 否则可能导致剪贴板记录丢失</br>2. v1.4.0及以上版本 Linux用户需手动安装clipboard-event-handler-linux至usr/bin目录 详见插件官网指南</br>3. 插件使用过程中遇到任何问题, 请到论坛发布页回帖或加入QQ群反馈",
"version": 2
}