Skip to content

Commit

Permalink
Traktor: Cleanup in X11 UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
apistol78 committed May 1, 2024
1 parent fa1a2c0 commit fdace59
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 120 deletions.
8 changes: 2 additions & 6 deletions code/Ui/X11/BitmapX11.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -11,10 +11,8 @@
#include <cairo.h>
#include "Ui/Itf/ISystemBitmap.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

class BitmapX11 : public ISystemBitmap
{
Expand All @@ -35,6 +33,4 @@ class BitmapX11 : public ISystemBitmap
cairo_surface_t* m_surface = nullptr;
};

}
}

7 changes: 2 additions & 5 deletions code/Ui/X11/ClipboardX11.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -9,10 +9,8 @@
#include "Core/Serialization/DeepClone.h"
#include "Ui/X11/ClipboardX11.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

void ClipboardX11::destroy()
{
Expand Down Expand Up @@ -59,5 +57,4 @@ Ref< const drawing::Image > ClipboardX11::getImage() const
return m_image;
}

}
}
7 changes: 2 additions & 5 deletions code/Ui/X11/ClipboardX11.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,10 +10,8 @@

#include "Ui/Itf/IClipboard.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

/*!
* \ingroup UI
Expand Down Expand Up @@ -44,5 +42,4 @@ class ClipboardX11 : public IClipboard
Ref< const drawing::Image > m_image;
};

}
}
8 changes: 4 additions & 4 deletions code/Ui/X11/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void Context::setFocus(WidgetData* widget)

m_focused->focus = false;

XEvent xevent;
XEvent xevent = {};
xevent.type = FocusOut;
dispatch(m_focused->window, FocusOut, true, xevent);

Expand All @@ -154,7 +154,7 @@ void Context::setFocus(WidgetData* widget)

XSetInputFocus(m_display, m_focused->window, RevertToNone, CurrentTime);

XEvent xevent;
XEvent xevent = {};
xevent.type = FocusIn;
dispatch(m_focused->window, FocusIn, true, xevent);
}
Expand All @@ -180,7 +180,7 @@ void Context::dispatch(XEvent& xe)

m_focused->focus = false;

XEvent xevent;
XEvent xevent = {};
xevent.type = FocusOut;
dispatch(m_focused->window, FocusOut, true, xevent);

Expand All @@ -191,7 +191,7 @@ void Context::dispatch(XEvent& xe)
m_focused = b->second.widget;
m_focused->focus = true;

XEvent xevent;
XEvent xevent = {};
xevent.type = FocusIn;
dispatch(focusWindow, FocusIn, true, xevent);
}
Expand Down
9 changes: 3 additions & 6 deletions code/Ui/X11/DialogX11.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -14,10 +14,8 @@
#include "Ui/X11/DialogX11.h"
#include "Ui/X11/Timers.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

DialogX11::DialogX11(Context* context, EventSubject* owner)
: WidgetX11Impl< IDialog >(context, owner)
Expand Down Expand Up @@ -174,7 +172,7 @@ void DialogX11::setMinSize(const Size& minSize)

void DialogX11::setText(const std::wstring& text)
{
std::string cs = wstombs(text);
const std::string cs = wstombs(text);
const char* csp = cs.c_str();

XTextProperty tp;
Expand Down Expand Up @@ -217,5 +215,4 @@ void DialogX11::setVisible(bool visible)
}
}

}
}
8 changes: 2 additions & 6 deletions code/Ui/X11/DialogX11.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -11,10 +11,8 @@
#include "Ui/Itf/IDialog.h"
#include "Ui/X11/WidgetX11Impl.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

class DialogX11 : public WidgetX11Impl< IDialog >
{
Expand Down Expand Up @@ -44,6 +42,4 @@ class DialogX11 : public WidgetX11Impl< IDialog >
bool m_modal;
};

}
}

4 changes: 2 additions & 2 deletions code/Ui/X11/EventLoopX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool EventLoopX11::process(EventSubject* owner)
m_context->dispatch(e);
}

double dt = m_timer.getDeltaTime();
const double dt = m_timer.getDeltaTime();
Timers::getInstance().update(dt);

return !m_terminated;
Expand All @@ -134,7 +134,7 @@ int32_t EventLoopX11::execute(EventSubject* owner)

pendingMotion.type = 0;

int fd = ConnectionNumber(m_context->getDisplay());
const int fd = ConnectionNumber(m_context->getDisplay());
bool idle = true;

while (!m_terminated)
Expand Down
18 changes: 7 additions & 11 deletions code/Ui/X11/FormX11.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -18,12 +18,10 @@
#include "Ui/Itf/ISystemBitmap.h"
#include "Ui/X11/FormX11.h"

namespace traktor
namespace traktor::ui
{
namespace ui
namespace
{
namespace
{

bool haveProperty(Display* display, const Atom* properties, unsigned long nproperties, const char* tokenName)
{
Expand All @@ -36,7 +34,7 @@ bool haveProperty(Display* display, const Atom* properties, unsigned long nprope
return false;
}

}
}

FormX11::FormX11(Context* context, EventSubject* owner)
: WidgetX11Impl< IForm >(context, owner)
Expand Down Expand Up @@ -95,7 +93,7 @@ void FormX11::setText(const std::wstring& text)
{
WidgetX11Impl< IForm >::setText(text);

std::string cs = wstombs(text);
const std::string cs = wstombs(text);
const char* csp = cs.c_str();

XTextProperty tp;
Expand Down Expand Up @@ -176,7 +174,7 @@ void FormX11::maximize()

void FormX11::minimize()
{
XEvent event;
XEvent event = {};
event.xclient.type = ClientMessage;
event.xclient.window = m_data.window;
event.xclient.message_type = XInternAtom(m_context->getDisplay(), "_NET_WM_STATE", False);
Expand All @@ -189,7 +187,7 @@ void FormX11::minimize()

void FormX11::restore()
{
XEvent event;
XEvent event = {};
event.xclient.type = ClientMessage;
event.xclient.window = m_data.window;
event.xclient.message_type = XInternAtom(m_context->getDisplay(), "_NET_WM_STATE", False);
Expand Down Expand Up @@ -268,6 +266,4 @@ void FormX11::showProgress(int32_t current, int32_t total)
{
}

}
}

12 changes: 3 additions & 9 deletions code/Ui/X11/FormX11.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef traktor_ui_FormX11_H
#define traktor_ui_FormX11_H
#pragma once

#include "Ui/Itf/IForm.h"
#include "Ui/X11/WidgetX11Impl.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

class FormX11 : public WidgetX11Impl< IForm >
{
Expand Down Expand Up @@ -46,8 +43,5 @@ class FormX11 : public WidgetX11Impl< IForm >
Atom m_atomWmDeleteWindow;
};

}
}

#endif // traktor_ui_FormX11_H

17 changes: 8 additions & 9 deletions code/Ui/X11/Timers.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "Core/Assert.h"
#include "Core/Containers/AlignedVector.h"
#include "Core/Containers/StaticVector.h"
#include "Ui/X11/Timers.h"

namespace traktor
namespace traktor::ui
{
namespace ui
{

Timers& Timers::getInstance()
{
Expand All @@ -23,7 +21,7 @@ Timers& Timers::getInstance()

int32_t Timers::bind(int32_t interval, const std::function< void() >& fn)
{
int32_t id = m_nid++;
const int32_t id = m_nid++;
T_FATAL_ASSERT(m_timers.find(id) == m_timers.end());

Timer& t = m_timers[id];
Expand All @@ -36,26 +34,27 @@ int32_t Timers::bind(int32_t interval, const std::function< void() >& fn)

void Timers::unbind(int32_t id)
{
size_t nr = m_timers.erase(id);
const size_t nr = m_timers.erase(id);
T_FATAL_ASSERT(nr > 0);
m_nid++;
}

void Timers::update(double s)
{
AlignedVector< std::function< void() > > fns;
StaticVector< std::function< void() >, 16 > fns;
for (auto& it : m_timers)
{
Timer& t = it.second;
if ((t.until -= s) <= 0.0)
{
t.until = t.interval / 1000.0;
fns.push_back(t.fn);
if (fns.full())
break;
}
}
for (auto fn : fns)
fn();
}

}
}
8 changes: 2 additions & 6 deletions code/Ui/X11/Timers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* TRAKTOR
* Copyright (c) 2022 Anders Pistol.
* Copyright (c) 2022-2024 Anders Pistol.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
Expand All @@ -10,12 +10,9 @@

#include <functional>
#include <map>
#include <vector>

namespace traktor
namespace traktor::ui
{
namespace ui
{

class Timers
{
Expand All @@ -40,5 +37,4 @@ class Timers
int32_t m_nid = 1;
};

}
}
Loading

0 comments on commit fdace59

Please sign in to comment.