Skip to content

Commit

Permalink
- Cleanup, changes to window move/resize/etc
Browse files Browse the repository at this point in the history
- Fix CEF render frame not expanding with window size
- Add actual release build code to makefile
  • Loading branch information
valarnin committed Apr 14, 2020
1 parent 4d04ddc commit 95c2ba3
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 96 deletions.
4 changes: 0 additions & 4 deletions cef/draw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ void DrawArea::SetSize(int width, int height)
this->texture = malloc(width * height * 4);
this->width = width;
this->height = height;
if (this->pixbuf != NULL)
{
//@TODO: Uhh, should probably free pixbuf but no clue how?
}
this->pixbuf = gdk_pixbuf_new_from_data((const guchar*)this->texture, GDK_COLORSPACE_RGB, true, 8, width, height, width*4, NULL, NULL);
}
}
Expand Down
19 changes: 19 additions & 0 deletions cef/fetch-required-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

CEF_BUILD='cef_binary_81.2.15%2Bge07275d%2Bchromium-81.0.4044.92_linux64_minimal'
CEF_FOLDER='cef_binary_81.2.15+ge07275d+chromium-81.0.4044.92_linux64_minimal'
CEF_URL="http://opensource.spotify.com/cefbuilds/${CEF_BUILD}.tar.bz2"

if [[ ! -f "v8_context_snapshot.bin" ]]; then
mkdir 'cef-project' &> /dev/null
echo 'Fetching required CEF binaries'
curl -ocef-project/tmp.tar.bz2 "${CEF_URL}" &> /dev/null
cd cef-project
echo 'Extracting and moving'
tar xf tmp.tar.bz2
mv ${CEF_FOLDER}/Release/* ../
mv ${CEF_FOLDER}/Resources/* ../
echo 'Cleaning up'
cd ..
rm -rf cef-project
fi
6 changes: 5 additions & 1 deletion cef/hudkit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ void Hudkit::OnContextInitialized()

CefRefPtr<CefCommandLine> command_line = CefCommandLine::GetGlobalCommandLine();

CefRefPtr<BrowserHandler> handler(new BrowserHandler(false, new HudkitRenderHandler(hudkitWindow.drawArea)));
HudkitRenderHandler* renderHandler = new HudkitRenderHandler(hudkitWindow.drawArea);

hudkitWindow.CEFRenderHandler = renderHandler;

CefRefPtr<BrowserHandler> handler(new BrowserHandler(false, renderHandler));

CefBrowserSettings browser_settings;

Expand Down
5 changes: 5 additions & 0 deletions cef/hudkit.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public:
{
return this;
}
virtual void OnBeforeCommandLineProcessing(const CefString &process_type, CefRefPtr<CefCommandLine> command_line)
OVERRIDE
{
command_line->AppendSwitchWithValue("autoplay-policy", "no-user-gesture-required");
}

// CefBrowserProcessHandler methods:
virtual void OnContextInitialized() OVERRIDE;
Expand Down
1 change: 1 addition & 0 deletions cef/hudkit_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,6 @@ void HudkitConfig::WriteConfig()

std::ofstream output(file);
output << json;
output.flush();
output.close();
}
123 changes: 40 additions & 83 deletions cef/hudkit_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <gtk/gtk.h>
#include <keybinder-3.0/keybinder.h>

int handle_gtk_quit();

HudkitWindow::HudkitWindow(HudkitConfig &config) : config(config)
{
frame_time = std::chrono::nanoseconds(1000000000 / fps);
Expand Down Expand Up @@ -75,9 +73,6 @@ void HudkitWindow::Run()
g_signal_connect(G_OBJECT(gtkWindow), "screen-changed",
G_CALLBACK(&HudkitWindow::__handle_screen_changed), this);

g_signal_connect(G_OBJECT(gtkWindow), "configure-event",
G_CALLBACK(&HudkitWindow::__handle_configure_event), this);

gtk_main_iteration_do(true);

destroyed = false;
Expand All @@ -87,6 +82,7 @@ void HudkitWindow::Run()
auto frameStart = std::chrono::high_resolution_clock::now();

UpdateDecorationSize();
UpdateConfig();

if (resizePending)
{
Expand All @@ -112,6 +108,8 @@ void HudkitWindow::Run()
std::this_thread::sleep_for(frame_time - frameTime);
}
}

config.WriteConfig();
}

void HudkitWindow::Close()
Expand Down Expand Up @@ -155,76 +153,8 @@ void HudkitWindow::__handle_screen_changed(GtkWidget *widget, GdkScreen *old_scr
gtk_widget_set_visual(widget, gdk_screen_get_rgba_visual(screen));
}

void HudkitWindow::__handle_configure_event(GtkWindow *window, GdkEvent *event, gpointer data)
{
static int skippedEvents = 0;
static bool lastLockedState = false;
static bool firstAfterLock = false;

if (skippedEvents < 2)
{
++skippedEvents;
return;
}

HudkitWindow *instance = (HudkitWindow *)data;

if (event->configure.send_event == 0)
{
if (lastLockedState != instance->lockedState)
{
lastLockedState = instance->lockedState;
if (instance->lockedState)
{
firstAfterLock = true;
}
return;
}
bool resize = false;

int x = event->configure.x;
int y = event->configure.y;
int w = event->configure.width;
int h = event->configure.height;

if (!firstAfterLock)
{
x += instance->decorationSizeLeft;
y += instance->decorationSizeTop;
}
firstAfterLock = false;

printf("config event, %i %i %i %i, %i %i, %i\n", x, y, w, h, event->configure.x, event->configure.y, instance->lockedState);

if (instance->config.GetX() != x)
{
instance->config.SetX(x);
}
if (instance->config.GetY() != y)
{
instance->config.SetY(y);
}
if (instance->config.GetWidth() != w)
{
instance->config.SetWidth(w);
resize = true;
}
if (instance->config.GetHeight() != h)
{
instance->config.SetHeight(h);
resize = true;
}

if (resize)
{
instance->resizePending = true;
}
}
}

void HudkitWindow::__handle_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
handle_gtk_quit();
HudkitWindow *instance = (HudkitWindow *)data;
instance->destroyed = true;
}
Expand All @@ -235,6 +165,42 @@ void HudkitWindow::__handle_hotkey(const char *keystring, void *data)
instance->ToggleMoveResize();
}

void HudkitWindow::UpdateConfig()
{
GtkAllocation allocation;
int x, y;

gdk_window_get_origin(gdkWindow, &x, &y);
gtk_widget_get_allocation(widgetWindow, &allocation);

int w = allocation.width;
int h = allocation.height;
if (config.GetX() != x)
{
config.SetX(x);
}
if (config.GetY() != y)
{
config.SetY(y);
}

bool resized = false;
if (config.GetWidth() != w)
{
config.SetWidth(w);
resized = true;
}
if (config.GetHeight() != h)
{
config.SetHeight(h);
resized = true;
}
if (resized)
{
drawArea.SetSize(config.GetWidth(), config.GetHeight());
}
}

void HudkitWindow::UpdateDecorationSize()
{
if (!haveDecorationSizes && gtk_window_get_resizable(gtkWindow))
Expand Down Expand Up @@ -273,21 +239,13 @@ void HudkitWindow::EnableMoveResize()
{
if (lockedState)
{
int hx, hy, hw, hh;

gtk_window_get_position(gtkWindow, &hx, &hy);
gtk_window_get_size(gtkWindow, &hw, &hh);

gdk_window_hide(gdkWindow);
gtk_window_set_keep_above(gtkWindow, true);
gdk_window_set_override_redirect(gdkWindow, false);
gtk_window_set_decorated(gtkWindow, true);
gtk_window_set_accept_focus(gtkWindow, true);
gtk_window_set_resizable(gtkWindow, true);
gdk_window_show(gdkWindow);

movePending = true;

gdk_window_input_shape_combine_region(gdkWindow, NULL, 0, 0);

lockedState = false;
Expand All @@ -301,11 +259,11 @@ void HudkitWindow::DisableMoveResize()
int hx, hy, hw, hh;

gtk_window_get_position(gtkWindow, &hx, &hy);
gtk_window_move(gtkWindow, hx + decorationSizeLeft, hy + decorationSizeTop);
gtk_window_get_size(gtkWindow, &hw, &hh);

gdk_window_hide(gdkWindow);
gtk_window_set_keep_above(gtkWindow, true);
gdk_window_set_override_redirect(gdkWindow, true);
gtk_window_set_decorated(gtkWindow, false);
gtk_window_set_accept_focus(gtkWindow, false);
gtk_window_set_resizable(gtkWindow, false);
Expand All @@ -315,7 +273,6 @@ void HudkitWindow::DisableMoveResize()
cairo_region_destroy(region);
gdk_window_show(gdkWindow);

movePending = true;
lockedState = true;
}
}
5 changes: 3 additions & 2 deletions cef/hudkit_window.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "draw.hh"
#include "hudkit_config.hh"
#include "render_handler.hh"
#include <chrono>

class HudkitWindow {
Expand All @@ -17,7 +18,8 @@ public:
void DisableMoveResize();
void EnableMoveResize();
GtkWidget* widgetWindow;
void UpdateDecorationSize();
void UpdateDecorationSize(), UpdateConfig();
HudkitRenderHandler* CEFRenderHandler;
protected:
bool resizePending = false, movePending = false;
int decorationSizeTop, decorationSizeRight, decorationSizeBottom, decorationSizeLeft;
Expand All @@ -29,7 +31,6 @@ protected:
std::chrono::nanoseconds frame_time;
void DrawWindow();
static void __handle_screen_changed(GtkWidget *widget, GdkScreen *old_screen, gpointer userdata);
static void __handle_configure_event(GtkWindow *window, GdkEvent *event, gpointer data);
static void __handle_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data);
static void __handle_hotkey(const char* keystring, void* data);
bool destroyed = true, lockedState = false, haveDecorationSizes = false;
Expand Down
15 changes: 9 additions & 6 deletions cef/makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
hudkit: main.cc
@mkdir -p build
clang++ -g \
clang++ \
main.cc \
hudkit.cc \
browser_handler.cc \
Expand All @@ -18,10 +18,13 @@ hudkit: main.cc
-lcef_dll_wrapper \
-lcef \
-std=c++17
cp -r cef-project/Release/*.so build/
cp -r cef-project/Release/*.bin build/
cp -r cef-project/Release/swiftshader build/
cp -r cef-project/Resources/* build/
cp fetch-required-files.sh build/
cd build && ./fetch-required-files.sh

clean:
rm -rf build
rm build/hudkit
rm build/fetch-required-files.sh
rm build/release.tar.gz

dist:
cd build && tar zcf release.tar.gz hudkit fetch-required-files.sh

0 comments on commit 95c2ba3

Please sign in to comment.