forked from Shinonome/dots-hyprland
quickshell clipboard
This commit is contained in:
@@ -62,6 +62,7 @@ Singleton {
|
||||
property list<string> excludedSites: [ "quora.com" ]
|
||||
property QtObject prefix: QtObject {
|
||||
property string action: "/"
|
||||
property string clipboard: ":"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,10 @@ import Quickshell.Wayland
|
||||
import Quickshell.Hyprland
|
||||
|
||||
Scope {
|
||||
id: overviewScope
|
||||
property bool dontAutoCancelSearch: false
|
||||
Variants {
|
||||
id: overviewVariants
|
||||
model: Quickshell.screens
|
||||
PanelWindow {
|
||||
id: root
|
||||
@@ -50,7 +53,14 @@ Scope {
|
||||
Connections {
|
||||
target: GlobalStates
|
||||
function onOverviewOpenChanged() {
|
||||
delayedGrabTimer.start()
|
||||
if (!GlobalStates.overviewOpen) {
|
||||
overviewScope.dontAutoCancelSearch = false;
|
||||
} else {
|
||||
if (!overviewScope.dontAutoCancelSearch) {
|
||||
searchWidget.cancelSearch()
|
||||
}
|
||||
delayedGrabTimer.start()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,6 +77,10 @@ Scope {
|
||||
implicitWidth: columnLayout.width
|
||||
implicitHeight: columnLayout.height
|
||||
|
||||
function setSearchingText(text) {
|
||||
searchWidget.setSearchingText(text);
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: columnLayout
|
||||
visible: GlobalStates.overviewOpen
|
||||
@@ -84,6 +98,7 @@ Scope {
|
||||
}
|
||||
|
||||
SearchWidget {
|
||||
id: searchWidget
|
||||
panelWindow: root
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
onSearchingTextChanged: (text) => {
|
||||
@@ -163,5 +178,27 @@ Scope {
|
||||
GlobalStates.superReleaseMightTrigger = false
|
||||
}
|
||||
}
|
||||
GlobalShortcut {
|
||||
name: "overviewClipboardToggle"
|
||||
description: qsTr("Toggle clipboard query on overview widget")
|
||||
|
||||
onPressed: {
|
||||
if (GlobalStates.overviewOpen) {
|
||||
GlobalStates.overviewOpen = false;
|
||||
return;
|
||||
}
|
||||
for (let i = 0; i < overviewVariants.instances.length; i++) {
|
||||
let panelWindow = overviewVariants.instances[i];
|
||||
if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) {
|
||||
overviewScope.dontAutoCancelSearch = true;
|
||||
panelWindow.setSearchingText(
|
||||
ConfigOptions.search.prefix.clipboard
|
||||
);
|
||||
GlobalStates.overviewOpen = true;
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ RippleButton {
|
||||
|
||||
RowLayout {
|
||||
id: rowLayout
|
||||
spacing: 10
|
||||
spacing: iconLoader.sourceComponent === null ? 0 : 10
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: root.horizontalMargin + root.buttonHorizontalPadding
|
||||
anchors.rightMargin: root.horizontalMargin + root.buttonHorizontalPadding
|
||||
@@ -76,7 +76,9 @@ RippleButton {
|
||||
Loader {
|
||||
id: iconLoader
|
||||
active: true
|
||||
sourceComponent: root.materialSymbol == "" ? iconImageComponent : materialSymbolComponent
|
||||
sourceComponent: root.materialSymbol !== "" ? materialSymbolComponent :
|
||||
root.itemIcon !== "" ? iconImageComponent :
|
||||
null
|
||||
}
|
||||
|
||||
Component {
|
||||
@@ -111,6 +113,7 @@ RippleButton {
|
||||
StyledText {
|
||||
Layout.fillWidth: true
|
||||
id: nameText
|
||||
textFormat: Text.PlainText // TODO: make cliphist entry highlighting working
|
||||
font.pixelSize: Appearance.font.pixelSize.normal
|
||||
font.family: Appearance.font.family[root.fontType]
|
||||
color: Appearance.m3colors.m3onSurface
|
||||
|
||||
@@ -24,6 +24,21 @@ Item { // Wrapper
|
||||
implicitHeight: searchWidgetContent.implicitHeight + Appearance.sizes.elevationMargin * 2
|
||||
|
||||
property string mathResult: ""
|
||||
property bool lastQueryWasClipboard: false
|
||||
|
||||
onShowResultsChanged: {
|
||||
lastQueryWasClipboard = false;
|
||||
}
|
||||
function cancelSearch() {
|
||||
searchInput.selectAll()
|
||||
root.searchingText = ""
|
||||
}
|
||||
|
||||
function setSearchingText(text) {
|
||||
searchInput.text = text;
|
||||
root.searchingText = text;
|
||||
}
|
||||
|
||||
property var searchActions: [
|
||||
{
|
||||
action: "img",
|
||||
@@ -194,7 +209,7 @@ Item { // Wrapper
|
||||
Layout.leftMargin: 15
|
||||
iconSize: Appearance.font.pixelSize.huge
|
||||
color: Appearance.m3colors.m3onSurface
|
||||
text: "search"
|
||||
text: root.searchingText.startsWith(ConfigOptions.search.prefix.clipboard) ? 'content_paste_search' : 'search'
|
||||
}
|
||||
TextField { // Search box
|
||||
id: searchInput
|
||||
@@ -219,13 +234,6 @@ Item { // Wrapper
|
||||
}
|
||||
|
||||
onTextChanged: root.searchingText = text
|
||||
Connections {
|
||||
target: root
|
||||
function onVisibleChanged() {
|
||||
searchInput.selectAll()
|
||||
root.searchingText = ""
|
||||
}
|
||||
}
|
||||
|
||||
onAccepted: {
|
||||
if (appResults.count > 0) {
|
||||
@@ -279,10 +287,31 @@ Item { // Wrapper
|
||||
|
||||
model: ScriptModel {
|
||||
id: model
|
||||
values: {
|
||||
values: { // Search results are handled here
|
||||
////////////////// Skip? //////////////////
|
||||
if(root.searchingText == "") return [];
|
||||
|
||||
// Start math calculation, declare special result objects
|
||||
///////////// Special cases ///////////////
|
||||
if (root.searchingText.startsWith(ConfigOptions.search.prefix.clipboard)) { // Clipboard
|
||||
if (!root.lastQueryWasClipboard) {
|
||||
root.lastQueryWasClipboard = true;
|
||||
Cliphist.refresh(); // Refresh clipboard entries
|
||||
}
|
||||
const searchString = root.searchingText.slice(ConfigOptions.search.prefix.clipboard.length);
|
||||
return Cliphist.fuzzyQuery(searchString).map(entry => {
|
||||
return {
|
||||
name: entry.replace(/^\s*\S+\s+/, ""),
|
||||
clickActionName: qsTr("Copy"),
|
||||
type: `#${entry.match(/^\s*(\S+)/)?.[1] || ""}`,
|
||||
execute: () => {
|
||||
Hyprland.dispatch(`exec echo '${StringUtils.shellSingleQuoteEscape(entry)}' | cliphist decode | wl-copy`);
|
||||
}
|
||||
};
|
||||
}).filter(Boolean);
|
||||
}
|
||||
|
||||
|
||||
////////////////// Init ///////////////////
|
||||
nonAppResultsTimer.restart();
|
||||
const mathResultObject = {
|
||||
name: root.mathResult,
|
||||
@@ -322,10 +351,9 @@ Item { // Wrapper
|
||||
})
|
||||
.filter(Boolean);
|
||||
|
||||
// Init result array
|
||||
let result = [];
|
||||
|
||||
// Add filtered application entries
|
||||
//////////////// Apps //////////////////
|
||||
result = result.concat(
|
||||
AppSearch.fuzzyQuery(root.searchingText)
|
||||
.map((entry) => {
|
||||
@@ -335,23 +363,20 @@ Item { // Wrapper
|
||||
})
|
||||
);
|
||||
|
||||
// Add launcher actions
|
||||
////////// Launcher actions ////////////
|
||||
result = result.concat(launcherActionObjects);
|
||||
|
||||
// Insert math result before command if search starts with a number
|
||||
/////////// Math result & command //////////
|
||||
const startsWithNumber = /^\d/.test(root.searchingText);
|
||||
if (startsWithNumber)
|
||||
if (startsWithNumber) {
|
||||
result.push(mathResultObject);
|
||||
|
||||
// Command
|
||||
result.push(commandResultObject);
|
||||
|
||||
// If not already added, add math result after command
|
||||
if (!startsWithNumber) {
|
||||
result.push(commandResultObject);
|
||||
} else {
|
||||
result.push(commandResultObject);
|
||||
result.push(mathResultObject);
|
||||
}
|
||||
|
||||
// Web search
|
||||
///////////////// Web search ////////////////
|
||||
result.push({
|
||||
name: root.searchingText,
|
||||
clickActionName: qsTr("Search"),
|
||||
@@ -369,7 +394,8 @@ Item { // Wrapper
|
||||
return result;
|
||||
}
|
||||
}
|
||||
delegate: SearchItem {
|
||||
|
||||
delegate: SearchItem { // The selectable item for each search result
|
||||
entry: modelData
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user