From 523f0a6a45ad1054f7021a4f8872d84d6469d2b0 Mon Sep 17 00:00:00 2001 From: Sylvain78 Date: Thu, 17 Jul 2025 19:40:56 +0200 Subject: [PATCH 1/2] Watch on path instead of node (except when storing attributes) rationale : when vim modifies a file it creates a new file then rename it. So inode moves, and watching old inode doesn't detect the change. --- bepdf/Makefile | 7 ++++--- bepdf/beos/EntryChangedMonitor.cpp | 27 +++++++++++++-------------- bepdf/beos/EntryChangedMonitor.h | 9 ++++----- bepdf/beos/PDFWindow.cpp | 8 ++++++++ 4 files changed, 29 insertions(+), 22 deletions(-) diff --git a/bepdf/Makefile b/bepdf/Makefile index e9f8719..4e2551a 100644 --- a/bepdf/Makefile +++ b/bepdf/Makefile @@ -112,7 +112,8 @@ SYSTEM_INCLUDE_PATHS = ../xpdf \ ../xpdf/goo \ ../xpdf/splash \ ../xpdf/xpdf \ - /system/develop/headers/private/interface + /system/develop/headers/private/interface \ + /system/develop/headers/private/storage # Additional paths paths to look for local headers. These use the form # #include "header". Directories that contain the files in SRCS are @@ -135,7 +136,7 @@ LOCALES = ca cs de el en_AU en_GB en es fi fr fur hi id ja pl pt pt_BR ro ru sv # use. For example, setting DEFINES to "DEBUG=1" will cause the compiler # option "-DDEBUG=1" to be used. Setting DEFINES to "DEBUG" would pass # "-DDEBUG" on the compiler's command line. -DEFINES = +DEFINES = # Specify the warning level. Either NONE (suppress all warnings), # ALL (enable all warnings), or leave blank (enable default warnings). @@ -147,7 +148,7 @@ SYMBOLS := # Includes debug information, which allows the binary to be debugged easily. # If set to "TRUE", debug info will be created. -DEBUGGER := +DEBUGGER := # Specify any additional compiler flags to be used. COMPILER_FLAGS = -Wno-write-strings diff --git a/bepdf/beos/EntryChangedMonitor.cpp b/bepdf/beos/EntryChangedMonitor.cpp index 984fc5c..3db00d9 100644 --- a/bepdf/beos/EntryChangedMonitor.cpp +++ b/bepdf/beos/EntryChangedMonitor.cpp @@ -42,38 +42,37 @@ void EntryChangedMonitor::StartWatching(entry_ref *ref) { mEntryRef = *ref; mActive = true; - BNode node(ref); - if (node.InitCheck() == B_OK && - node.GetNodeRef(&mNodeRef) == B_OK) { - watch_node(&mNodeRef, B_WATCH_STAT, this); + BEntry entry(ref); + BPath path; + if (entry.InitCheck() == B_OK && + entry.GetPath(&path) == B_OK) { + BPathMonitor::StartWatching(path.Path(),B_WATCH_STAT,this); } } void EntryChangedMonitor::StopWatching() { if (mActive) { - watch_node(&mNodeRef, B_STOP_WATCHING, this); + BEntry entry(&mEntryRef); + BPath path; + entry.GetPath(&path); + BPathMonitor::StopWatching(path.Path(), this); + mActive = false; } } void EntryChangedMonitor::MessageReceived(BMessage* msg) { - if (msg->what != B_NODE_MONITOR) + if (msg->what != B_PATH_MONITOR) return; int32 opcode; if (msg->FindInt32("opcode", &opcode) != B_OK) return; - if (opcode != B_STAT_CHANGED) + if (opcode != B_STAT_CHANGED ) return; - // Haiku sends a B_STAT_CHANGED notification - // when attributes are changed too - // this leads to an infinite loop, as - // BePDF changes file attributes after - // loading a file. - // TODO check if file has changed and only - // then notify the listener + NotifyListener(); } void EntryChangedMonitor::NotifyListener() { diff --git a/bepdf/beos/EntryChangedMonitor.h b/bepdf/beos/EntryChangedMonitor.h index 270c9fa..ac8c944 100644 --- a/bepdf/beos/EntryChangedMonitor.h +++ b/bepdf/beos/EntryChangedMonitor.h @@ -23,10 +23,10 @@ #ifndef ENTRY_CHANGED_MONITOR_H #define ENTRY_CHANGED_MONITOR_H -#include -#include #include -#include +#include +#include +#include class EntryChangedListener { public: @@ -59,7 +59,6 @@ class EntryChangedMonitor : public BHandler { EntryChangedListener* mListener; bool mActive; entry_ref mEntryRef; - node_ref mNodeRef; }; -#endif \ No newline at end of file +#endif diff --git a/bepdf/beos/PDFWindow.cpp b/bepdf/beos/PDFWindow.cpp index 2e84ee4..128ac3f 100644 --- a/bepdf/beos/PDFWindow.cpp +++ b/bepdf/beos/PDFWindow.cpp @@ -344,6 +344,10 @@ bool PDFWindow::IsCurrentFile(entry_ref *ref) const { /////////////////////////////////////////////////////////// bool PDFWindow::LoadFile(entry_ref *ref, const char *ownerPassword, const char *userPassword, bool *encrypted) { if (mMainView != NULL) { + // Haiku sends a B_STAT_CHANGED notification + // when attributes are changed too + // that's why we stop watching when changing attributes + mEntryChangedMonitor.StopWatching(); StoreFileAttributes(); CleanUpBeforeLoad(); // load new file @@ -354,6 +358,10 @@ bool PDFWindow::LoadFile(entry_ref *ref, const char *ownerPassword, const char * InitAfterOpen(); return true; } + //If unable to load the new ref, watch again + entry_ref oldRef; + if (mCurrentFile.GetRef(&oldRef) == B_OK) + mEntryChangedMonitor.StartWatching(&oldRef); } return false; } From f151f21f10e7913b32fabb4520921dbb8b9d04fa Mon Sep 17 00:00:00 2001 From: Anarchos Date: Thu, 17 Jul 2025 19:46:51 +0000 Subject: [PATCH 2/2] typo --- bepdf/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bepdf/Makefile b/bepdf/Makefile index 4e2551a..62e465c 100644 --- a/bepdf/Makefile +++ b/bepdf/Makefile @@ -136,7 +136,7 @@ LOCALES = ca cs de el en_AU en_GB en es fi fr fur hi id ja pl pt pt_BR ro ru sv # use. For example, setting DEFINES to "DEBUG=1" will cause the compiler # option "-DDEBUG=1" to be used. Setting DEFINES to "DEBUG" would pass # "-DDEBUG" on the compiler's command line. -DEFINES = +DEFINES = # Specify the warning level. Either NONE (suppress all warnings), # ALL (enable all warnings), or leave blank (enable default warnings).