core: add more flexible positioning and scaling (#138)

* feat: use axis scroller to change scale

* feat: add option -s to set scale and -u to set radius

* Optimize optarg conversion
This commit is contained in:
DreamMaoMao 2025-09-16 05:45:32 +08:00 committed by GitHub
parent d6a1363a86
commit 6f32582d22
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 59 additions and 5 deletions

View file

@ -406,7 +406,7 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
cairo_scale(PCAIRO, 1, 1); cairo_scale(PCAIRO, 1, 1);
cairo_arc(PCAIRO, CLICKPOS.x, CLICKPOS.y, 105 / SCALEBUFS.x, 0, 2 * M_PI); cairo_arc(PCAIRO, CLICKPOS.x, CLICKPOS.y, m_iCircleRadius + 5 / SCALEBUFS.x, 0, 2 * M_PI);
cairo_clip(PCAIRO); cairo_clip(PCAIRO);
cairo_fill(PCAIRO); cairo_fill(PCAIRO);
@ -422,11 +422,11 @@ void CHyprpicker::renderSurface(CLayerSurface* pSurface, bool forceInactive) {
cairo_matrix_t matrix; cairo_matrix_t matrix;
cairo_matrix_init_identity(&matrix); cairo_matrix_init_identity(&matrix);
cairo_matrix_translate(&matrix, CLICKPOSBUF.x + 0.5f, CLICKPOSBUF.y + 0.5f); cairo_matrix_translate(&matrix, CLICKPOSBUF.x + 0.5f, CLICKPOSBUF.y + 0.5f);
cairo_matrix_scale(&matrix, 0.1f, 0.1f); cairo_matrix_scale(&matrix, 1.0 / m_fZoomScale, 1.0 / m_fZoomScale);
cairo_matrix_translate(&matrix, (-CLICKPOSBUF.x / SCALEBUFS.x) - 0.5f, (-CLICKPOSBUF.y / SCALEBUFS.y) - 0.5f); cairo_matrix_translate(&matrix, (-CLICKPOSBUF.x / SCALEBUFS.x) - 0.5f, (-CLICKPOSBUF.y / SCALEBUFS.y) - 0.5f);
cairo_pattern_set_matrix(PATTERN, &matrix); cairo_pattern_set_matrix(PATTERN, &matrix);
cairo_set_source(PCAIRO, PATTERN); cairo_set_source(PCAIRO, PATTERN);
cairo_arc(PCAIRO, CLICKPOS.x, CLICKPOS.y, 100 / SCALEBUFS.x, 0, 2 * M_PI); cairo_arc(PCAIRO, CLICKPOS.x, CLICKPOS.y, m_iCircleRadius / SCALEBUFS.x, 0, 2 * M_PI);
cairo_clip(PCAIRO); cairo_clip(PCAIRO);
cairo_paint(PCAIRO); cairo_paint(PCAIRO);
@ -756,4 +756,18 @@ void CHyprpicker::initMouse() {
finish(); finish();
}); });
m_pPointer->setAxis([this](CCWlPointer* r, uint32_t time, uint32_t axis, wl_fixed_t value) {
if (axis != WL_POINTER_AXIS_VERTICAL_SCROLL)
return;
double delta = wl_fixed_to_double(value);
if (delta < 0)
m_fZoomScale = std::min(m_fZoomScale + 1.0, 100.0);
else
m_fZoomScale = std::max(m_fZoomScale - 1.0, 1.0);
markDirty();
});
} }

View file

@ -49,6 +49,8 @@ class CHyprpicker {
bool m_bUseLowerCase = false; bool m_bUseLowerCase = false;
bool m_bRunning = true; bool m_bRunning = true;
float m_fZoomScale = 10.0;
int m_iCircleRadius = 100;
std::vector<std::unique_ptr<SMonitor>> m_vMonitors; std::vector<std::unique_ptr<SMonitor>> m_vMonitors;
std::vector<std::unique_ptr<CLayerSurface>> m_vLayerSurfaces; std::vector<std::unique_ptr<CLayerSurface>> m_vLayerSurfaces;

View file

@ -18,6 +18,8 @@ static void help() {
<< " -t | --no-fractional | Disable fractional scaling support\n" << " -t | --no-fractional | Disable fractional scaling support\n"
<< " -d | --disable-preview | Disable live preview of color\n" << " -d | --disable-preview | Disable live preview of color\n"
<< " -l | --lowercase-hex | Outputs the hexcode in lowercase\n" << " -l | --lowercase-hex | Outputs the hexcode in lowercase\n"
<< " -s | --scale=scale | Set the zoom scale (between 1 and 10)\n"
<< " -u | --radius=radius | Set the circle radius (between 1 and 1000)\n"
<< " -V | --version | Print version info\n"; << " -V | --version | Print version info\n";
} }
@ -39,9 +41,11 @@ int main(int argc, char** argv, char** envp) {
{"disable-preview", no_argument, nullptr, 'd'}, {"disable-preview", no_argument, nullptr, 'd'},
{"lowercase-hex", no_argument, nullptr, 'l'}, {"lowercase-hex", no_argument, nullptr, 'l'},
{"version", no_argument, nullptr, 'V'}, {"version", no_argument, nullptr, 'V'},
{"scale", required_argument, nullptr, 's'},
{"radius", required_argument, nullptr, 'u'},
{nullptr, 0, nullptr, 0}}; {nullptr, 0, nullptr, 0}};
int c = getopt_long(argc, argv, ":f:hnbarzqvtdlV", long_options, &option_index); int c = getopt_long(argc, argv, ":f:hnbarzqvtdlVs:u:", long_options, &option_index);
if (c == -1) if (c == -1)
break; break;
@ -77,7 +81,41 @@ int main(int argc, char** argv, char** envp) {
std::cout << "hyprpicker v" << HYPRPICKER_VERSION << "\n"; std::cout << "hyprpicker v" << HYPRPICKER_VERSION << "\n";
exit(0); exit(0);
} }
case 's': {
float value;
auto result = std::from_chars(optarg, optarg + strlen(optarg), value);
if (result.ec != std::errc() || result.ptr != optarg + strlen(optarg)) {
std::cerr << "Invalid scale value: " << optarg << "\n";
exit(1);
}
if (value < 1.0f || value > 10.0f) {
std::cerr << "Scale must be between 1 and 10!\n";
exit(1);
}
g_pHyprpicker->m_fZoomScale = value;
break;
}
case 'u': {
int value;
auto result = std::from_chars(optarg, optarg + strlen(optarg), value);
if (result.ec != std::errc() || result.ptr != optarg + strlen(optarg)) {
std::cerr << "Invalid radius value: " << optarg << "\n";
exit(1);
}
if (value < 1 || value > 1000) {
std::cerr << "Radius must be between 1 and 1000!\n";
exit(1);
}
g_pHyprpicker->m_iCircleRadius = value;
break;
}
default: help(); exit(1); default: help(); exit(1);
} }
} }