Skip to content

Commit

Permalink
Linting and Fixing CMakeLists.txt.
Browse files Browse the repository at this point in the history
  • Loading branch information
SySyAli committed Jan 6, 2024
1 parent 9396b07 commit 37b1d01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
23 changes: 11 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,22 @@ add_executable(desktop_screentime main.cpp
IWindowInterface.cpp
)

# Link SQLite3 to the executable
target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES})


# Link pthread and X11 for Linux
if(UNIX AND NOT APPLE)
# Link libraries to the executable
if(MSVC)
# Using Microsoft Visual C++
target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES})
elseif(APPLE)
# For macOS, link Application Services framework
target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} "-framework ApplicationServices")
elseif(UNIX AND NOT APPLE)
# For Linux, link pthread and possibly X11
if(X11_FOUND)
target_link_libraries(desktop_screentime PRIVATE ${X11_LIBRARIES} pthread)
target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} ${X11_LIBRARIES} pthread)
else()
target_link_libraries(desktop_screentime PRIVATE pthread)
target_link_libraries(desktop_screentime PRIVATE ${SQLite3_LIBRARIES} pthread)
endif()
endif()

# Link Application Services for macOS
if(APPLE)
target_link_libraries(desktop_screentime "-framework ApplicationServices")
endif()

# Testing Executable
# Define the source files and dependencies for the executable
Expand Down
13 changes: 8 additions & 5 deletions IWindowInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,19 @@ void LinuxTracker::startTracking()

#ifdef __APPLE__

std::string getActiveWindowTitleMac() {
CFArrayRef windowList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
std::string getActiveWindowTitleMac()
{
CFArrayRef windowList
= CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly, kCGNullWindowID);
if (windowList) {
for (CFIndex i = 0; i < CFArrayGetCount(windowList); i++) {
CFDictionaryRef windowInfo = (CFDictionaryRef)CFArrayGetValueAtIndex(windowList, i);
CFNumberRef windowLayer = (CFNumberRef)CFDictionaryGetValue(windowInfo, kCGWindowLayer);
int layer;
CFNumberGetValue(windowLayer, kCFNumberIntType, &layer);
if (layer == 0) { // Check if it's the active window layer
CFStringRef windowTitle = (CFStringRef)CFDictionaryGetValue(windowInfo, kCGWindowName);
CFStringRef windowTitle
= (CFStringRef)CFDictionaryGetValue(windowInfo, kCGWindowName);
if (windowTitle) {
char title[256];
CFStringGetCString(windowTitle, title, 256, kCFStringEncodingUTF8);
Expand All @@ -195,7 +198,8 @@ std::string getActiveWindowTitleMac() {
return "";
}

void MacOSTracker::startTracking() {
void MacOSTracker::startTracking()
{
AppEntry prevEntry;
while (tracking) {
std::string title = getActiveWindowTitleMac();
Expand Down Expand Up @@ -236,6 +240,5 @@ void MacOSTracker::startTracking() {

std::this_thread::sleep_for(std::chrono::seconds(1));
}

}
#endif

0 comments on commit 37b1d01

Please sign in to comment.