Separate widget close clicks from right-button desktop dragging (by Codex)
Prepare verified release / draft (push) Waiting to run

This commit is contained in:
Codex committed 2026-10-31 09:06:12 +01:00
1 parent 12e3e52537
commit b2a6300aad
6 files changed
+86 -10

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-3.0-only
cmake_minimum_required(VERSION 3.24)
project(OpenBMH VERSION 1.0.1 LANGUAGES CXX C)
project(OpenBMH VERSION 1.0.2 LANGUAGES CXX C)
if(APPLE)
# Enable native languages before dependencies/subdirectories inherit rules.
enable_language(OBJC OBJCXX)
+8
View File
@@ -1,3 +1,11 @@
# OpenBMH 1.0.2
A left click on an open desktop widget's upper-left close button now hides that widget through the normal validated layout transaction. The close button no longer starts a drag or shows the moving outline. Moving an element with the right mouse button remains available.
The close action consumes its matching mouse release even if the engine has already removed the widget, preventing an accidental click on an icon underneath. The automation and macOS keyboard fixes from 1.0.1 remain unchanged.
---
# OpenBMH 1.0.1
The automatic-lineup monitor now draws the selected formation from the actual manager formation table. Outdoor, indoor and custom formation slots retain their original coordinates and palette. Dragging a desktop element shows the original yellow outline, which disappears when the drag ends.
+4
View File
@@ -39,3 +39,7 @@ Calendar epoch regression covers the original CD and Diamond parameters, engine
The desktop feedback test checks selected saved formations against their original table, compares changed miniature pixels, and checks the original yellow outline during a drag and its removal afterward. Private CD and Diamond render captures use the original assets. The SDL lifetime test checks initialization before the picker scope, normal destruction and failed initialization cleanup.
A macOS-only native Cocoa test initializes SDL before the native picker lifecycle, checks regular activation, creates a keyboard-focused window and verifies that a Cocoa key event produces both SDL key and text events. This automated native event test supplements human keyboard QA; it is not a claim of physical typing on the user's machine.
## 1.0.2 close-button regression
The desktop feedback test checks that the left corner requests removal instead of entering drag mode, that the remaining layout chain is intact, and that the release after acknowledgement does not activate an underlying icon. A subsequent independent click remains usable. Right-button movement and its temporary yellow outline remain covered. The user confirmed the 1.0.1 automation and Mac keyboard corrections.
+38 -9
View File
@@ -327,8 +327,30 @@ std::optional<DeskItem> DesktopScreen::folder_child_at(int x,int y) const {
return std::nullopt;
}
DeskRequest DesktopScreen::close_drawer(const DeskItem& item) {
if (item.id < 1 || item.id >= 54 || item.kind < 50 || item.kind > 71 || !item.open) return {};
const auto& record = state_.layout_records[size_t(item.id)];
const int previous = record[6], next = record[5];
if (previous >= 54 || next >= 54 || record[12] != item.kind ||
state_.layout_records[size_t(previous)][5] != item.id ||
(next != 0 && state_.layout_records[size_t(next)][6] != item.id)) return {};
auto action = request(DeskRequestKind::change_layout, item, 2);
action.layout_operation = DeskLayoutOperation::toggle_quickbar_drawer;
action.layout_target_item = item.id;
for (size_t i = 0; i < 54; ++i)
std::copy(state_.layout_records[i].begin(), state_.layout_records[i].end(), action.layout_before.begin() + i * 16);
action.layout_after = action.layout_before;
action.layout_after[size_t(previous) * 16 + 5] = uint8_t(next);
if (next != 0) action.layout_after[size_t(next) * 16 + 6] = uint8_t(previous);
action.layout_after[size_t(item.id) * 16 + 5] = 0xff;
action.layout_after[size_t(item.id) * 16 + 6] = 0xff;
sound_ids_.push_back(12);
pending_ = action;
return action;
}
DeskRequest DesktopScreen::pointer_down(int x, int y, bool right) {
if (pending_) return {};
if (pending_ || drawer_close_release_pending_) return {};
if (socket_release_pending_) return {}; // DeskDate waits here for the first RMB release.
sample_shortcut_pointer(x, y);
shortcut_hover_record_ = -1; // DeskDate clears its tooltip on event2/event8 before dispatch.
@@ -366,19 +388,22 @@ DeskRequest DesktopScreen::pointer_down(int x, int y, bool right) {
const int inset = item.kind >= 50 && !item.open ? 8 : 0;
if (item.disabled || x < item.x || y < item.y || x >= item.x + item.width - inset ||
y >= item.y + item.height - inset) continue;
if (!right && item.kind >= 50 && item.open && state_.drawer_handles &&
x <= item.x + 3 && y <= item.y + 3) {
auto action = close_drawer(item);
drawer_close_release_pending_ = action.kind != DeskRequestKind::none;
return action;
}
if (right && !state_.drawer_handles) return {};
if (right && bin_mode_ && item.kind!=12) return {};
if (!right && item.kind==55 && item.open && !state_.national_team &&
x-item.x-4>34 && x-item.x-4<87) return {}; // Original ticket-price scale.
if (!right && item.kind==64 && item.open) return {}; // Source automation controls remain clicks.
const bool drawer_handle=item.kind>=50&&state_.drawer_handles&&x<=item.x+3&&y<=item.y+3;
if(item.kind>=50&&!drawer_handle&&!right) return {};
if(!right&&!drawer_handle) return {}; // Source LMB activates; RMB starts a drag.
if (!right) return {}; // LMB closes/activates; RMB alone starts a drag.
layout_drag_ = LayoutDrag{item.id, x - item.x, y - item.y, item.x, item.y, -1, false, false, drawer_handle, right};
layout_preview_ = state_;
// RemovesBinModeIcon/RestoresChildBinMode run at RMB press, even if no motion follows.
// The existing LMB handle drag differs from that Source path; do not
// invent its sound mapping here.
if (right) sound_ids_.insert(sound_ids_.end(), {12, 15});
return {};
}
@@ -386,7 +411,7 @@ DeskRequest DesktopScreen::pointer_down(int x, int y, bool right) {
}
bool DesktopScreen::pointer_move(int x, int y) {
if (pending_ || socket_release_pending_) return false;
if (pending_ || socket_release_pending_ || drawer_close_release_pending_) return false;
if (!layout_drag_ || !layout_preview_) return sample_shortcut_pointer(x, y);
auto& drag = *layout_drag_;
auto found = std::find_if(layout_preview_->items.begin(), layout_preview_->items.end(),
@@ -404,6 +429,10 @@ bool DesktopScreen::pointer_move(int x, int y) {
}
DeskRequest DesktopScreen::pointer_up(int x, int y, bool right) {
if (drawer_close_release_pending_) {
if (!right) drawer_close_release_pending_ = false;
return {}; // The close owns its release even after the widget was removed by ACK.
}
if (socket_release_pending_) {
if (right) socket_release_pending_ = false;
return {}; // First socket RMB release is only the Source wait barrier.
@@ -621,9 +650,9 @@ DeskRequest DesktopScreen::click(int x, int y, bool right) {
}
if (item.disabled || right) return {};
if (item.kind < 50) return request(item.kind == 12 ? DeskRequestKind::advance_turn : DeskRequestKind::open_menu, item);
// DeskDate only handles Ticket/Calendar/Automation body clicks;
// drawer open/close is exclusively the compact quickbar operation.
if (item.open && state_.drawer_handles && x <= item.x + 3 && y <= item.y + 3) return {};
// The corner closes through the same transaction as the quickbar.
if (item.open && state_.drawer_handles && x <= item.x + 3 && y <= item.y + 3)
return close_drawer(item);
if (item.kind == 58 && item.open) return request(DeskRequestKind::advance_turn, item);
if (item.kind == 55 && item.open && !state_.national_team && x - item.x - 4 > 34 && x - item.x - 4 < 87)
return request(DeskRequestKind::change_ticket_price, item, (x - item.x - 4 - 35) / 3 + 8);
+2
View File
@@ -71,6 +71,8 @@ private:
mutable std::vector<uint8_t> sound_ids_;
struct LayoutDrag { int item=-1, grab_x=0, grab_y=0, start_x=0, start_y=0, folder=-1; bool moved=false, folder_child=false, drawer_handle=false, right_button=false; };
std::optional<LayoutDrag> layout_drag_;
bool drawer_close_release_pending_ = false;
DeskRequest close_drawer(const DeskItem& item);
std::optional<DeskState> layout_preview_;
void text(Image&, int x, int baseline, std::string_view, uint8_t color, int right = -1) const;
void sprite_text(Image&, int x, int baseline, std::string_view, int font) const;
+33
View File
@@ -6,6 +6,7 @@
#include "formats/savestate.hpp"
#include "formats/executable_layout.hpp"
#include <filesystem>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <stdexcept>
@@ -57,6 +58,38 @@ int main(int argc,char**argv)try{
const auto second=DesktopScreen(data,state).render();
check(first.pixels!=second.pixels,"changing selected formation left the monitor unchanged");
capture(output,"formation-1.ppm",first,palette);capture(output,"formation-2.ppm",second,palette);
state.drawer_handles=true;
state.items={{2,20,20,32,25,0,0,0,false,false},{1,20,20,173,40,64,0,0,true,false}};
state.layout_records[0][5]=2;
state.layout_records[2][5]=1; state.layout_records[2][6]=0;
state.layout_records[1][5]=0; state.layout_records[1][6]=2;
state.layout_records[1][12]=64; state.layout_records[1][13]=0x80;
DesktopScreen widget_drag(data,state);
widget_drag.pointer_down(21,21,true);
widget_drag.pointer_move(61,61);
const auto widget_move=widget_drag.pointer_up(61,61,true);
check(widget_move.kind==DeskRequestKind::change_layout && widget_move.layout_operation==DeskLayoutOperation::move_item,
"right-button widget movement was replaced by closing");
DesktopScreen close(data,state);
capture(output,"close-before.ppm",close.render(),palette);
const auto removal=close.pointer_down(21,21,false);
check(removal.kind==DeskRequestKind::change_layout &&
removal.layout_operation==DeskLayoutOperation::toggle_quickbar_drawer &&
removal.layout_target_item==1,"left corner did not request widget removal");
check(removal.layout_after[2*16+5]==0 && removal.layout_after[16+5]==0xff &&
removal.layout_after[16+6]==0xff,"corner removal corrupted the remaining layout chain");
check(close.state_json().find("\"dragging_item\":null")!=std::string::npos,
"close corner incorrectly entered drag mode");
check(!close.pointer_move(100,100),"close press turned into movement");
auto removed=state; removed.revision=state.revision+1; removed.items.erase(removed.items.begin()+1);
for(size_t i=0;i<54;++i)std::copy_n(removal.layout_after.begin()+i*16,16,removed.layout_records[i].begin());
close.acknowledge(removed);
check(close.pointer_up(21,21,false).kind==DeskRequestKind::none,
"close release activated the icon underneath the removed widget");
capture(output,"close-after.ppm",close.render(),palette);
check(close.pointer_up(21,21,false).kind==DeskRequestKind::open_menu,
"close release barrier consumed a subsequent independent click");
state.layout_records={}; state.layout_records[0][5]=1;
state.items={{1,20,20,32,25,0,0,0,false,false}};state.drawer_handles=true;
DesktopScreen drag(data,state);const auto normal=drag.render();
const auto idle=drag.state_json();