Skip to content

Commit

Permalink
simulate fake mouse events to prevent screen turnoff when playing video
Browse files Browse the repository at this point in the history
  • Loading branch information
kanishka-linux committed Apr 20, 2019
1 parent 7102e27 commit 8ab951a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
13 changes: 12 additions & 1 deletion kawaii_player/guisignals.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import platform
import urllib.parse
from functools import partial
from PyQt5 import QtCore, QtGui
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import pyqtSlot, pyqtSignal
from settings_widget import LoginPCToPC

Expand All @@ -47,6 +47,7 @@ class GUISignals(QtCore.QObject):
queue_signal = pyqtSignal(str)
queue_delete = pyqtSignal(int)
display_signal = pyqtSignal(str)
mouse_move_signal = pyqtSignal(tuple)

def __init__(self, uiwidget, mw):
QtCore.QObject.__init__(self)
Expand Down Expand Up @@ -74,6 +75,7 @@ def __init__(self, uiwidget, mw):
self.queue_delete.connect(self.queue_delete_signal)
self.display_signal.connect(self.display_signal_string)
self.first_time = True
self.mouse_move_signal.connect(self.mouse_move_function)

def generate_preview(self, picn, length, change_aspect, tsec, counter, x, y, source_val):
self.preview_signal.emit(picn, length, change_aspect, tsec, counter, x, y, source_val)
Expand Down Expand Up @@ -138,6 +140,9 @@ def delete_queue_item(self, val):

def display_string(self, val):
self.display_signal.emit(val)

def mouse_move_method(self, event):
self.mouse_move_signal.emit(event)

@staticmethod
def update_opengl_widget(val):
Expand Down Expand Up @@ -222,6 +227,12 @@ def wrapper(*args, **kargs):
def preview_generated_new(self, picn, length, change_aspect, tsec, counter, x, y, source_val):
ui.slider.preview_generated(picn, length, change_aspect, tsec, counter, x, y, source_val)

@pyqtSlot(tuple)
def mouse_move_function(self, event_tuple):
widget, event = event_tuple
print(event)
QtWidgets.QApplication.postEvent(widget, event)

@pyqtSlot(str)
def queue_signal_generated(self, val):
ui.list2.queue_item()
Expand Down
33 changes: 32 additions & 1 deletion kawaii_player/mpv_opengl.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ def __init__(self, parent=None, ui=None, logr=None, tmp=None, mpv_api=None, app=
self.sub_id = -1
self.audio_id = -1
self.dpr = 1.0
#self.cursor = self.getCursor()

def init_opengl_cb(self):
self.mpv = MPV(**self.args_dict)
Expand Down Expand Up @@ -625,14 +626,18 @@ def time_observer(self, _name, value):
if abs(value - gui.progress_counter) >= 0.5:
display_string = self.display_play_pause_string(value)
file_size = self.mpv.get_property('file-size')
value_int = int(value)
if file_size:
file_size = round((file_size)/(1024*1024), 2)
display_string = "{} Size: {} M".format(display_string, file_size)
if not gui.frame1.isHidden() and not self.seek_now:
gui.slider.valueChanged.emit(int(value))
gui.slider.valueChanged.emit(value_int)
gui.gui_signals.display_string((display_string))
if not gui.new_tray_widget.isHidden():
gui.new_tray_widget.update_signal.emit(display_string, int(value))

if value_int % 30 == 0:
self.send_fake_event()
if self.audio and int(value) in range(0, 3):
self.mpv.command("audio-add", self.audio, "select")
logger.debug("{} {}".format("adding..audio..", self.audio))
Expand All @@ -658,6 +663,32 @@ def time_observer(self, _name, value):
gui.epnfound_now_start_prefetch(finalUrl, row, type_val)
self.prefetch_url = None

def send_fake_event(self):
pos = self.cursor().pos()
new_point = QtCore.QPoint(pos.x() + 1, pos.y()+1)
self.cursor().setPos(new_point)
mouseReleaseEvent = QtGui.QMouseEvent(
QtCore.QEvent.MouseButtonRelease,
new_point,
QtCore.Qt.LeftButton,
QtCore.Qt.LeftButton,
QtCore.Qt.NoModifier,
)
self.ui.gui_signals.mouse_move_method((self, mouseReleaseEvent))

if self.hasFocus() and self.ui.fullscreen_video and not self.ui.frame1.isHidden():
pos = self.cursor().pos()
new_point = QtCore.QPoint(pos.x() + 1, pos.y()+1)
self.cursor().setPos(new_point)
mouseMoveEvent = QtGui.QMouseEvent(
QtCore.QEvent.MouseMove,
new_point,
QtCore.Qt.NoButton,
QtCore.Qt.NoButton,
QtCore.Qt.NoModifier,
)
self.ui.gui_signals.mouse_move_method((self, mouseMoveEvent))

def rem_properties(self, final_url, rem_quit, seek_time):
self.ui.history_dict_obj_libmpv.update(
{
Expand Down

0 comments on commit 8ab951a

Please sign in to comment.